重用UIWebView会导致崩溃 [英] Reusing UIWebView is causing crashes

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

问题描述

我已经读过重用UIWebViews是一种不好的做法。我在工作中继承的一些代码是将各种内容推送到UIWebView。 Powerpoint,Word文档和视频。这一切在正常情况下都能正常工作。当我们过快地切换UIWebView中的内容时,它会转储。

I've read that reusing UIWebViews is kind of a bad practice. Some code I inherited at work is pushing a variety of content to a UIWebView. Powerpoints, Word documents, and video. This all works just fine under normal circumstances. When we get to switching out the content in the UIWebView too fast, it dumps.

我的webView被设置为属性。它很好地融入了IB。从我们的tableView正常选择加载本地内容就好了。它需要快速选择相同的单元格或多个组合才能使其崩溃。

My webView is set as a property. It is hooked up in IB just fine. Normal selection from our tableView loads local content just fine. It takes rapid fire selection of either the same cell or combinations of multiple to get it to crash.

我可以为webViewDidFailWithError捕获一些错误消息。但即使没有崩溃,这些也会触发。
这是错误的本地化字符串。

I can capture some error messages for it for the webViewDidFailWithError. But those will trigger even without a crash. Here is the error localized string.

The operation couldn’t be completed. (NSURLErrorDomain error -999.)

当应用程序最终崩溃时,它会在这个愚蠢的WebCore上爆炸错误。

When the app does finally crash, it blows up on this goofy WebCore error.

如果有人有任何链接或一些代码示例如何处理这个我会很感激。也许是一个例子,如何最好地重用我的webView属性而不会搞砸。

If anyone has any links or some code examples how to handle this I would appreciate it. Maybe an example how to best reuse my webView property without blowing things up.

我会加载一些代码,但有很多与webView本身无关。所有推送到webView的内容都是通过 [self.webView loadRequest:request]; 完成的,请求是NSURLRequest,填充了本地内容的路径。

I would load some of my code, but there is a lot going on not related to the webView itself. All content being pushed to the webView is done via [self.webView loadRequest:request]; with the request being an NSURLRequest filled with the path to the local content.

如果有人能帮我解决这个问题,我将非常感激。手指越过简单的东西。

I will be very appreciative if anyone can help me out on this one. Fingers crossed for something simple.

推荐答案

我不确定这种方式是解决问题的最佳方式,但是它似乎确实运作良好。简短,甜蜜,而且很有效。

I'm not certain this way is the "best" way to solve the issue, but it does seem to be working quite well. Short, sweet, and it works.

我使用tableView禁用了userInteraction,更新了webView中的内容。因为你必须将它混合在一起,所以在这里或那里错过一个水龙头可能不会错过。所以现在,这是修复。

I disabled userInteraction with the tableView that updates the content in the webView. Since you have to mash on it so much, missing a tap here or there probably won't be missed. So for now, this is the fix.

#pragma mark -
#pragma mark UIWebViewDelegate methods

-(void)webViewDidStartLoad:(UIWebView *)webView {
    [self.tableView setUserInteractionEnabled:NO];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.tableView setUserInteractionEnabled:YES];
}

// I re-enable on load failures as they can block you out entirely on fail
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    [self.tableView setUserInteractionEnabled:YES]; 
}

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

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