重用的 UIWebView 在 iPhone 上短暂显示之前加载的内容 [英] Reused UIWebView showing previous loaded content for a brief second on iPhone

查看:12
本文介绍了重用的 UIWebView 在 iPhone 上短暂显示之前加载的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个应用程序中,我重用了一个 webview.每次用户进入某个视图时,使用以下方法将缓存数据重新加载到 webview :-

In one of my apps I reuse a webview. Each time the user enters a certain view on reload cached data to the webview using the method :-

- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL

我等待回调调用

- (void) webViewDidFinishLoad:(UIWebView *)webView.

与此同时,我隐藏了 webview 并显示了一个正在加载"标签.只有当我收到 webViewDidFinishLoad 时,我才会显示 webview.

In the mean time I hide the webview and show a 'loading' label. Only when I receive webViewDidFinishLoad do I show the webview.

在我加载的新数据开始之前,我看到之前加载到 webview 的数据有很短的时间.

Many times what happens I see the previous data that was loaded to the webview for a brief second before the new data I loaded kicks in.

我已经在显示 webview 之前添加了 0.2 秒的延迟,但它没有帮助.

I already added a delay of 0.2 seconds before showing the webview but it didn't help.

有没有人知道如何解决这个问题,或者可能从 web 视图中清除旧数据而不释放并每次都分配它,而不是通过增加更多时间来解决这个问题?

Instead of solving this by adding more time to the delay does anyone know how to solve this issue or maybe clear old data from a webview without release and allocating it every time?

推荐答案

感谢 malaki1974,就我而言,我没有使用模态视图.当我在 WWDC 2010 上与一位 Apple 工程师坐在一起问他这个问题时,他的回答很简单:不要重复使用 UIWebView,这不是它们的使用方式."从那时起,我确保在分配新的 UIWebView 之前调用这组行

Thanks malaki1974, in my case I wasn't using a modal view. When I sat with an Apple engineer on WWDC 2010 and asked him this question his answer was simply: "Don't reuse UIWebViews, that's not how they were ment to be used." Since then I make sure to calls this set of lines before allocating a new UIWebView

[self.myWebView removeFromSuperview];
self.myWebView.delegate = nil;
[self.myWebView stopLoading];
[self.myWebView release];

这解决了问题.

这篇关于重用的 UIWebView 在 iPhone 上短暂显示之前加载的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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