EXC_BAD_ACCESS in UIWebView

自作多情 提交于 2019-11-29 20:18:52
Stephen Darlington

The scenario goes something like this:

  1. User enters screen with UIWebView. The UIViewController sets self as the delegate
  2. Web page starts downloading
  3. User exits screen
    3a. UIViewController gets deallocated
  4. UIWebView finishes loading and sends "I finished" message to its delegate...

You need to stop the UIWebView from loading its page and sets its delegate to nil before you deallocate the delegate.

It's almost 100% an error in your code. Errors in the iPhone SDK are quite rare and UIWebView has been tested quite good by many other developers.

EXC_BAD_ACCESS occurs usually when you try to access an already released object. Obviously if Apple's code is trying to do that you are the one who has released the object wrongly. Are you sure you don't have a -autorelease or -release too much?

Cesar Lou

I recently had a similar problem where my apps were crashing randomly. Turns out the problem was in using "onclick=" in the loaded HTML.

Replaced the onclick with simple <a href="javascript:some_script"> and the problem went away.

Hope this helps others who are experiencing the same issue with webviews.

Take a harder look inside the thing in your code that is implementing the UIWebViewDelegate protocol. In particular you want to look at whatever is handling webViewDidFinishLoad: You are trying to access a variable that's been released. Post the full source if you can, that will help us find it for you.

axe

I had a similar problem. I was using:

 [webView loadHTMLString:str baseURL:tmpUrl];

 [str release];

The release of "str" caused the error message "EXC_BAD_ACCESS"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!