何时在uiviewController上拨打DealLoc,当它被弹出时?
说如果我有这样的导航堆栈: uinavigationController-> viewController1-> viewController2 。当ViewController2弹出时,系统是否保证了下面方法的执行顺序?
- dealloc viewController2
- viewwillappear viewController1
我已经测试了一段时间,只看到 dreamloc 首先称为 dreamloc 可以保证,即,在ViewController2的 dealloc 之前,是否也可以调用ViewController1的ViewController1的 ViewWillAppear ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
There is no such guarantee of order, and it's even likely
viewWillAppear
of your ViewController1 is called beforeViewController2.dealloc
is called.原因是,根据自动发行池和内部参考,系统可能仍然对视图控制器进行引用,该视图控制器刚刚消失/当它调用视图控制器的 < em>大约要显示。
viewwillappear
如果在弹出viewController2时需要清理以进行清理,请实现
viewwilldisappear
/viewDidDisappear
。同样,不能保证vc2.viewwilldisappear
将在vc1.viewwillappear
之前被调用vc1.viewdidappear
(注意 did ,而不是最后一个中的)。There is no such guarantee of order, and it's even likely
viewWillAppear
of your ViewController1 is called beforeViewController2.dealloc
is called.The reason is that depending on autorelease pools and internal references, it's likely the system still has a reference to the view controller that is just disappearing/has just disappeared when it calls the
viewWillAppear
of the view controller that's about to get shown.If you require cleanup to be run when ViewController2 is popped, implement
viewWillDisappear
/viewDidDisappear
. Again, there is no guarantee thatvc2.viewWillDisappear
will be called beforevc1.viewWillAppear
, but you can rely onvc2.viewWillDisappear
getting called beforevc1.viewDidAppear
(noteDid
, notWill
in the last one).