Reused UIWebView showing previous loaded content for a brief second on iPhone(重用的 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 上短暂显示之前加载的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:重用的 UIWebView 在 iPhone 上短暂显示之前加载的内容
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
