什么时候调用UIViewController viewDidUnload? [英] When is UIViewController viewDidUnload called?

查看:105
本文介绍了什么时候调用UIViewController viewDidUnload?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:此问题已过时 - viewDidUnload 已弃用iOS 6。

Note: This question is outdated—viewDidUnload is deprecated iOS 6.

UIViewController的viewDidUnload何时自动被调用?是的,我知道,当视图卸载时。但是什么时候会自动发生?我该如何手动完成?谢谢。

When does UIViewController's viewDidUnload automatically get called? Yes I know, when the view unloads. But when does that happen automatically? How can I do it manually? Thanks.

推荐答案

如果在模拟器中发出内存警告(在菜单中查看),将调用任何视图控制器附加到不可见的视图。

If you issue a memory warning in the simulator (look in the menu), this will get called for any view controller attached to a view that is not visible.

这是因为默认情况下视图控制器已注册内存警告通知,并且任何当前未使用的视图都将被卸载通过视图控制器 - viewDidUnload方法在那里,你可以清理你想要的任何东西,以节省额外的内存(或者如果你保留了一些IBOutlets来帮助释放内存,否则将被卸载的视图释放)。

That's because view controllers by default are registered for memory warning notifications, and any view that is not currently being used will be unloaded by the view controller - the viewDidUnload method is there so that you can clean up anything else you would like, to save extra memory (or if you've retained some IBOutlets to help free up memory that would otherwise be released by the view being unloaded).

通常,您在dealloc中发布的任何IBOutlet也应该在此方法中释放(并且引用设置为nil)。

Generally any IBOutlets you release in dealloc, should also be released (and references set to nil) in this method.

这篇关于什么时候调用UIViewController viewDidUnload?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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