UIWebView EXC_BAD_ACCESS崩溃 [英] UIWebView EXC_BAD_ACCESS crash

查看:133
本文介绍了UIWebView EXC_BAD_ACCESS崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了使用UIWebView的应用程序崩溃。通常是在页面没有完全加载并且UIWebView被发送到stopLoading选择器时。或者当UIWebView完全加载页面时。我有 EXC_BAD_ACCESS 。 Stack看起来像这样:

I'm experiencing crashes of an app that uses UIWebView. Usually it's when page is not fully loaded and UIWebView is sent stopLoading selector. Or when UIWebView fully loaded page. I've got EXC_BAD_ACCESS. Stack looks like this:

#0  0x95bb7688 in objc_msgSend
#1  0x30a671db in -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:]
#2  0x3024a10d in __invoking___
#3  0x30249ff8 in -[NSInvocation invoke]
#4  0x358ab160 in HandleDelegateSource
#5  0x302452c1 in CFRunLoopRunSpecific
#6  0x30244628 in CFRunLoopRunInMode
#7  0x32044c31 in GSEventRunModal
#8  0x32044cf6 in GSEventRun
#9  0x309021ee in UIApplicationMain
#10 0x0000239c in main at main.m:13

对我来说最奇怪的是 webView:decisionPolicyForNavigationAction:request:frame:decisionListener:选择器发送到UIWebView,因为UIWebView文档中没有这样的选择器!仅适用于Cocoa(不是可可触摸)WebView。
我怀疑UIWebView或其委托有问题。但是我无法设置断点来观察它们。请告知我如何在这种情况下获得更多信息。

for me most strange thing here is webView:decidePolicyForNavigationAction:request:frame:decisionListener: selector sent to UIWebView, because there is no such selector in UIWebView documentation! Only for Cocoa (not cocoa touch) WebView. I suspect that there is something wrong with UIWebView or its delegate. But I can't set breakpoint to watch them. Please advise how I can get more info in this situation.

推荐答案

您必须在离开前停止加载webView并删除委托视图:

You have to stop loading the webView and remove the delegate before leaving the view:

// ARC (correct solution)
- (void)dealloc {
    [_webView setDelegate:nil];
    [_webView stopLoading];
}

// non ARC
- (void)dealloc {
    [webView setDelegate:nil];
    [webView stopLoading];
    [webView release];
    [super dealloc];
}

// ARC (older solution)
- (void)viewWillUnload {
    [webView setDelegate:nil];
    [webView stopLoading];
}

Apple文档说的是:
重要发布之前要为其设置委托的UIWebView实例,必须先将其委托属性设置为nil 。这可以在你的dealloc方法中完成。

What Apple documentation is saying: Important Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil. This can be done, for example, in your dealloc method.

这篇关于UIWebView EXC_BAD_ACCESS崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆