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

发布于 2024-12-11 11:03:48 字数 969 浏览 0 评论 0原文

我使用委托方法 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

请止步禁区 2024-12-18 11:03:48

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

[webview stopLoading];

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

[webview stopLoading];
平生欢 2024-12-18 11:03:48

我完全不知道为什么我会从 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.

花心好男孩 2024-12-18 11:03:48

检查你是否在控制器的 dealloc 方法中取消了 UIWebView 的 delegate 属性(当然如果这个控制器是 webview 的 delegate)。像这样:

- (void) viewDidLoad
{
    webView.delegate = self;
}
- (void) dealloc
{
    webView.delegate = nil;
}

来自 委托属性

重要。在释放已设置委托的 UIWebView 实例之前,必须首先将其委托属性设置为 nil。例如,这可以在 dealloc 方法中完成。

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:

- (void) viewDidLoad
{
    webView.delegate = self;
}
- (void) dealloc
{
    webView.delegate = nil;
}

From the Apple docs on the delegate property:

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.

眼趣 2024-12-18 11:03:48

导致此错误的另一个原因可能是在包含 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.

生死何惧 2024-12-18 11:03:48

我遇到了类似的错误:

***WebKit 丢弃了 webView 中未捕获的异常:decidePolicyForNavigationAction:frame:decisionListner: delegate: - [UIPopoverController dealloc] 在弹出窗口仍然可见时到达。

该问题似乎是由以下代码引起的:

UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];
[pc presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

显然,当例程退出时,pc 正在被释放。我更改了代码,使 pc 成为一个属性,WebKit 不再抱怨。

I got a similar error:

***WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:frame:decisionListner: delegate: - [UIPopoverController dealloc] reached while popover is still visible.

The problem seems to be caused by the following code:

UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];
[pc presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

Apparently, pc is being deallocated when the routine exits. I changed the code to make pc a property and WebKit stopped complaining.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文