清除委托
清除 UIWebView 委托的正确方法是什么?
在我的 dealloc 函数中,我添加了
[myWebView setDelegate:nil];
[myWebView release];
And 是第一个 ligne 必要的吗?
编辑:如果我的对象不是 UIWebView 而是 NSFetchedResultsController 该怎么办?
谢谢
What is the correct way to clear a UIWebView delegate ?
In my dealloc function, I added
[myWebView setDelegate:nil];
[myWebView release];
And is the first ligne necessary ?
EDIT : and what if my object was not a UIWebView but a NSFetchedResultsController
?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将委托设置为零是一回事。其他同样重要甚至更重要的是,当您不再关心结果并且即将释放包含 UIWebView 的视图时,如何干净地关闭正在加载的 UIWebView。
这是对上述问题和更多问题的一个非常好的答案:如何在 viewWillDisappear 中安全地关闭正在加载的 UIWebView?。它将很好地概述 UIWebView 的生命周期。
调用
stopLoading
的提示:在调用stopLoading
之前,您不必使用isLoading
检查是否正在加载任何内容 - 只需调用直接 stopLoading
,如果没有加载任何内容,它不会执行任何操作。Setting the delegate to nil is one thing. Other, quite as important or even more, is how to cleanly shut down a loading UIWebView in a case when you don't care about the result anymore and you're about to release a view containing your UIWebView.
Here is a really good answer to above questions and more: How to safely shut down a loading UIWebView in viewWillDisappear?. It'll give a good overview on UIWebView's life-cycle.
A hint on calling
stopLoading
: you don't have to check if anything is being loaded withisLoading
before callingstopLoading
- just callstopLoading
directly and it will do nothing if nothing is being loaded.在上面的代码的情况下。不,您可能不需要清除委托。
但是,如果您有 ClassA 和 ClassB,并且您已将 ClassA 设置为 ClassB 的委托,那么您需要小心的是......当 ClassA 被释放而 ClassB 仍在使用中时。
因此,为了处理这个问题,ClassA 会在 ClassA 的 dealloc 方法中清除 ClassB 的委托属性(本身)。
In the case of the code above. No, you probably don't need to clear the delegate.
But, if you have ClassA and ClassB, and you've set ClassA to be the delegate of ClassB, then what you need to be careful with is ... when ClassA is deallocated while ClassB is still in use.
So, to handle that, ClassA would clear (itself) from the delegate property of ClassB in the
dealloc
method for ClassA.我认为您只需要在发布之前取消所有请求即可:
干杯!
I think you need only to cancel all request before release it by:
Cheers!.