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

查看:21
本文介绍了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 中释放的任何 IBOutlets 也应该在此方法中释放(并将引用设置为 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天全站免登陆