关闭模态视图时清除 UIWebView 内容 (iPhone OS 3.0)
我目前有一个显示在模式视图中的 UIWebView。它基本上是一个详细视图,当用户单击链接时提供页面视图。当视图被关闭然后再次打开时(当用户单击另一个链接时),先前加载的内容仍然可见,并且新内容加载在最后内容的“顶部”。这是有道理的,因为 UIWebView 的实例在会话之间持续存在,并且仅在需要内存时才被释放。
但是,我想在模式视图关闭时完全清除 UIWebView,以便 1)清除内容并 2)释放内存。到目前为止我的研究和尝试还没有找到答案。这些链接对我不起作用:
我尝试过 [[NSURLCache sharedURLCache] removeAllCachedResponses];
并将 webView 设置为 nil 并在 modal-view-dismiss 时手动释放 webView无济于事。干瘪的群众有什么想法吗?
I currently have a UIWebView that is displayed within a modal view. It is basically a detail view that provides a view of a page when the user clicks a link. When the view is dismissed and then brought up again (when the user clicks another link), the previously-loaded content is still visible and the new content loads "on top" of the last content. This makes sense because the instance of the UIWebView persists between sessions and is only released when the memory is needed.
However, I would like to completely clear the UIWebView when the modal view is dismissed so that 1) content is cleared and 2) memory is freed. Thus far my research and attempts have not found an answer. These links haven't worked for me:
- is it possible to free memory of UIWebView?
- Reused UIWebView showing previous loaded content for a brief second on iPhone
I've tried [[NSURLCache sharedURLCache] removeAllCachedResponses];
and setting the webView to nil and manually releasing the webView upon modal-view-dismiss to no avail. Any thoughts from the wizened masses?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
评估 javascript 通常比加载新请求更快。
evaluating javascript is usually quicker than loading a new request.
就我而言,我需要立即清除网络视图的内容,并能够立即开始加载其他内容。加载空文档 HTML 字符串或使用 JavaScript 清除页面都没有达到预期的效果。相反,我使用:
这将视图清除为默认背景并按预期启动下一页的加载。
我希望这也对其他人有帮助。
In my case I needed to clear the web view from its contents instantaneously and be able to start loading something else right away. Neither loading an empty document HTML string nor clearing the page with JavaScript resulted in desired effect. Instead I used:
And this cleared the view to the default background and initiated next page's loading as expected.
I hope this helps someone else as well.
我更喜欢以下内容:
i prefer to the following:
有时
loadHTMLString
太慢。您还可以使用:我不确定这是否会释放大量内存......
Sometimes
loadHTMLString
is too slow. You also can use:I'm not sure if that will free up much memory though...
发布网络视图可能是最好的方法。如果视图位于视图层次结构中(具有超级视图),则必须调用removeFromSuperview 来让超级视图释放该视图。
您还可以为空文档加载 html 字符串:
Releasing the web view is probably the best approach. If a view is in a view hierarchy (has a superview) you must call removeFromSuperview to get the superview to release the view.
You could also load an html string for an empty document:
在某些情况下,drawonward 和 rob 建议的方法可能不起作用(可能与正在清除的页面上的 CSS 有关),但是这确实有效:
It seems under some circumstances the methods suggested by drawnonward and rob may not work (possibly something to do with CSS on the page that's being cleared), however this did work :