iOS 5 UIWebview 委托:WebKit 丢弃了 webView 中未捕获的异常:decidePolicyForNavigationAction

iOS 5 UIWebview Delegate: WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction(iOS 5 UIWebview 委托:WebKit 丢弃了 webView 中未捕获的异常:decidePolicyForNavigationAction)

本文介绍了iOS 5 UIWebview 委托:WebKit 丢弃了 webView 中未捕获的异常:decidePolicyForNavigationAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用委托方法 shouldStartLoadWithRequest 来捕获链接点击并处理我的应用程序内的特定情况,而不是允许 webView 导航到链接.在这段代码中,我试图将一个新的 ViewController 推送到堆栈上.在尝试推送视图后,我立即在控制台中收到以下消息崩溃:

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:

我的代码如下所示:

-(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.我得到相同的结果.我应该在这里处理任何其他情况吗?

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?

**刚想到这个.我试图推送的视图包含另一个 UIWebView.我应该在过渡之前对第一个 webView 做些什么吗?我只是测试推送一个不包含 webView 的不同视图控制器,它工作正常.

** 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.

推荐答案

我通过确保在继续之前停止 webview 上的所有先前请求来解决此问题:

I fixed this by ensuring that all previous requests on the webview were stopped before continuing:

[webview stopLoading];

这篇关于iOS 5 UIWebview 委托:WebKit 丢弃了 webView 中未捕获的异常:decidePolicyForNavigationAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:iOS 5 UIWebview 委托:WebKit 丢弃了 webView 中未捕获的异常:decidePolicyForNavigationAction

基础教程推荐