以编程方式创建 UIWebview 并使用它来做一些事情然后销毁它?
是否可以以编程方式创建一个隐藏的 UIWebView,然后在使用它时释放它(完全销毁它并重新分配所有内存)?如果是这样,您能给一些建议吗?谢谢!
Is it possible to create a hidden UIWebView programmatically and then release it(destroy it completely deallocating all of it's memory) when I have used it? If so, could you give some tips. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 UIWebView 对象的主要目的是呈现 html 内容时,您想要使用隐藏的 UIWebView 对象来执行某些任务似乎很奇怪。你的问题的答案是肯定的。您可以创建它们并以编程方式删除它们,就像 @Nil 提到的任何其他视图一样,但似乎您背后的主要目的是获取内容。如果是这样,您可以通过许多其他方式获取该内容,而无需创建
UIWebView
对象。您可以使用 NSString 的 initWithContentsOfURL:encoding:error: 方法将 url 的内容获取到可以解析和使用的字符串中。NSData
有类似的方法。然而,要使用这些,您必须在后台执行它们,否则它们将阻塞主线程。最明显、更好的方法是使用NSURLConnection
或其流行的对应项ASIHTTPRequest
。It seems odd that you want to use a hidden
UIWebView
object for some task when the main purpose of anUIWebView
object is to present the html content. The answer to your question is yes. You can create them and remove them programmatically just like any other view as @Nil has mentioned but it seems your main purpose behind this is to get the content. If that's so, you have many other ways you can get that content without having to create aUIWebView
object. You can useNSString
'sinitWithContentsOfURL:encoding:error:
method to get the contents of the url into a string which you can parse and use.NSData
has a similar method. However to use these you will have to perform them in the background otherwise they will block the main thread. The most obvious and better way would be to useNSURLConnection
or its popular counterpartASIHTTPRequest
.是的,您可以像任何其他 uiview 一样创建和销毁 uiwebview。
Yes, you can create and destroy a uiwebview as any other uiview.