解除模式视图后清除UIWebView内容(iPhone OS 3.0) [英] Clear UIWebView content upon dismissal of modal view (iPhone OS 3.0)

查看:72
本文介绍了解除模式视图后清除UIWebView内容(iPhone OS 3.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个UIWebView,它显示在模式视图中.它基本上是一个详细视图,当用户单击链接时提供页面视图.当视图被关闭然后再次显示时(当用户单击另一个链接时),以前加载的内容仍然可见,新内容将加载"到最后一个内容的顶部".这是有道理的,因为UIWebView的实例在会话之间保持不变,并且仅在需要内存时才释放.

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.

但是,我想在消除模式视图时完全清除UIWebView,以便1)清除内容并2)释放内存.到目前为止,我的研究和尝试还没有找到答案.这些链接对我不起作用:

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:

  1. 是否可以释放UIWebView的内存?
  2. 已重用的UIWebView,它显示以前的已加载在iPhone上短暂停留的内容
  1. is it possible to free memory of UIWebView?
  2. Reused UIWebView showing previous loaded content for a brief second on iPhone

我尝试了[[NSURLCache sharedURLCache] removeAllCachedResponses];并将webView设置为nil,并在模态视图关闭时手动释放了webView,但无济于事.广大群众有什么想法吗?

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视图可能是最好的方法.如果视图在视图层次结构中(具有超级视图),则必须调用removeFromSuperview来获取超级视图以释放视图.

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.

您还可以为空文档加载html字符串:

You could also load an html string for an empty document:

[webView loadHTMLString:@"<html><head></head><body></body></html>" baseURL:nil];

这篇关于解除模式视图后清除UIWebView内容(iPhone OS 3.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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