何时在uiviewController上拨打DealLoc,当它被弹出时?

发布于 2025-02-13 04:25:05 字数 423 浏览 1 评论 0 原文

说如果我有这样的导航堆栈: uinavigationController-> viewController1-> viewController2 。当ViewController2弹出时,系统是否保证了下面方法的执行顺序?

  1. dealloc viewController2
  2. viewwillappear viewController1

我已经测试了一段时间,只看到 dreamloc 首先称为 dreamloc 可以保证,即,在ViewController2的 dealloc 之前,是否也可以调用ViewController1的ViewController1的 ViewWillAppear

Say if I have a navigation stack like this: UINavigationController->ViewController1->ViewController2. When ViewController2 gets popped, does the system guarantee the executing order of below methods?

  1. dealloc of ViewController2
  2. viewWillAppear of ViewController1

I've tested for a while and only see dealloc is called first, but I don't know if this can be guaranteed, i.e., is it also possible ViewController1's viewWillAppear gets called before ViewController2's dealloc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一世旳自豪 2025-02-20 04:25:05

There is no such guarantee of order, and it's even likely viewWillAppear of your ViewController1 is called before ViewController2.dealloc is called.

原因是,根据自动发行池和内部参考,系统可能仍然对视图控制器进行引用,该视图控制器刚刚消失/当它调用视图控制器的 viewwillappear < em>大约要显示。

如果在弹出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 before ViewController2.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 that vc2.viewWillDisappear will be called before vc1.viewWillAppear, but you can rely on vc2.viewWillDisappear getting called before vc1.viewDidAppear (note Did, not Will in the last one).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文