iOS 5 UIWebview委托:WebKit在webView中丢弃了未捕获的异常:decisionPolicyForNavigationAction [英] iOS 5 UIWebview Delegate: WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction

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

问题描述

我正在使用委托方法 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中丢弃了未捕获的异常:decisionPolicyForNavigationAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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