iOS 5 UIWebview Delegate:WebKit 丢弃了 webView 中未捕获的异常:decidePolicyForNavigationAction
我使用委托方法 shouldStartLoadWithRequest
来捕获链接点击并处理应用程序内的特定情况,而不是允许 webView
导航到链接。在此代码中,我尝试将新的 ViewController 推送到堆栈上。在尝试推送视图后,我立即崩溃并在控制台中显示以下消息:
WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate:
我的代码如下所示:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if(decision logic){
MyViewController *vc = [[MyViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
return NO;
}
return YES;
}
我还尝试使用模式而不是推送新的 viewController
。我得到同样的结果。我还应该在这里处理其他情况吗?
**编辑:刚刚想到这一点。我尝试推送的视图包含另一个 UIWebView
。在转换之前我应该对第一个 webView
做一些事情吗?我只是测试推送一个不包含 webView
的不同视图控制器,它工作得很好。
I am using the delegate method shouldStartLoadWithRequest
to catch link clicks and handle specific cases inside my app instead of allowing the webView
to navigate to the link. In this code, I am attempting to push a new ViewController
onto the stack. Immediately after the attempt to push the view, I get a crash with the following message in my console:
WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate:
My code looks like this:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if(decision logic){
MyViewController *vc = [[MyViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
return NO;
}
return YES;
}
I have also tried using a modal instead of pushing a new viewController
. I get the same result. Is there any other scenarios I should be handling here?
**Edit: Just thought of this. The view I'm trying to push contains another UIWebView
. Should I be doing something to the first webView
before transitioning? I just testing pushing a different view controller that doesn't contain a webView
and it worked fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我通过确保在继续之前停止 webview 上的所有先前请求来修复此问题:
I fixed this by ensuring that all previous requests on the webview were stopped before continuing:
我完全不知道为什么我会从 Webkit 中收到此错误,但我追踪到它试图在带有 nil 键的字典中插入一个值。
I have absolutely no idea why I'm getting this error from Webkit, but I traced it down to trying to insert a value in a dictionary with a nil key.
检查你是否在控制器的 dealloc 方法中取消了 UIWebView 的 delegate 属性(当然如果这个控制器是 webview 的 delegate)。像这样:
来自 委托属性:
Check out if you nullify delegate property of UIWebView in its controller dealloc method (of course if this controller is webview's delegate). Like this:
From the Apple docs on the delegate property:
导致此错误的另一个原因可能是在包含 Web 视图的视图控制器中意外启用了自动布局。
这是我在 iOS5 上测试时发生的。
Yet another cause for this error can be the fact that Autolayout is accidentally left enabled in the viewcontroller containing the webview.
This happened to me while testing on iOS5.
我遇到了类似的错误:
该问题似乎是由以下代码引起的:
显然,当例程退出时,pc 正在被释放。我更改了代码,使 pc 成为一个属性,WebKit 不再抱怨。
I got a similar error:
The problem seems to be caused by the following code:
Apparently, pc is being deallocated when the routine exits. I changed the code to make pc a property and WebKit stopped complaining.