如何销毁由pushViewController添加的视图?
通过pushViewController
方法添加视图后,导航栏中将有一个后退按钮,用于将视图从堆栈中弹出。但是,iOS似乎在将视图从堆栈中弹出后不会销毁该视图,那么什么时候会销毁它呢?我们可以在弹出视图时手动销毁它吗?
After adding a view by pushViewController
method, there will be a back button in the navigation bar to pop the view off the stack. However, it seems that iOS won't destroy the view after popping it off the stack so when will it be destroyed? Can we destroy it manually when popping out the view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,模式是这样的:
换句话说,导航控制器将自己
retain
视图控制器,这意味着您还需要release
code> 你自己,因为有一个init
。导航控制器还将在适当的时候负责释放该控制器。Generally the pattern is like this:
In other words, the navigation controller will do its own
retain
of the view controller, which means you also need torelease
it yourself, since there's aninit
. The navigation controller will also take care of releasing this controller when appropriate.您应该在
UIViewController
子类中实现viewDidUnload
和dealloc
方法。当 UINavigationController 将视图控制器从其堆栈中弹出时,这些方法中的代码将被执行。
您应该阅读 iOS 视图控制器编程指南:导航控制器 来自 Apple iOS 开发人员库的文档以及
UINavigationController
和UIViewController< /code>
类,以便您更好地了解视图控制器生命周期以及发生各种应用程序事件时会发生什么。
You should implement the
viewDidUnload
anddealloc
methods within yourUIViewController
subclasses.When a
UINavigationController
pops a view controller off its stack the code within those methods will be executed.You should read the View Controller Programming Guide for iOS: Navigation Controllers documentation from Apple's iOS Developer Library as well as the class reference documentation for the
UINavigationController
andUIViewController
classes so that you will better understand the view controller life cycle and what to expect when various application events occur.