isMovingToParentViewController 总是为导航堆栈的根视图控制器返回 FALSE? [英] isMovingToParentViewController always returning FALSE for root view controller of a navigation stack?

查看:43
本文介绍了isMovingToParentViewController 总是为导航堆栈的根视图控制器返回 FALSE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定导航堆栈的根视图(顶级)控制器是否因最初呈现与未发现而出现的正确方法是什么?

What is the proper method to determine whether the root view (top level) controller of a navigation stack is appearing as a result of being initially presented vs. being uncovered?

iOS 文档建议在 viewWill/DidAppear: 中使用 isMovingToParentViewController 来做出决定.这适用于推送到堆栈上的视图控制器,但似乎总是为堆栈根视图控制器返回 FALSE.

The iOS documentation suggests using isMovingToParentViewController inside viewWill/DidAppear: to make that determination. This works for view controllers pushed on the stack, but appears to always return FALSE for the stack root view controller.

感谢您的帮助.

推荐答案

看起来有人回答了同样的问题:iOS: isMovingToParentViewController未按预期工作.

Looks like someone else has answered the same question: iOS: isMovingToParentViewController is not working as expected.

虽然这并不完全正确,但我认为,即使对于根视图,也可以多次调用 viewDidLoad.由于内存原因,它可能会被卸载,当它的子视图从导航堆栈中弹出时需要重新加载.

Though it is not entirely correct, I think, in that viewDidLoad may be called more than once, even for the root view. It may get unloaded for memory reasons, and need to be reloaded when its child view is popped from the nav stack.

如果您真的只想看到根控制器被添加一次,我会更改链接帖子中的解决方案以使用 static 变量而不是实例变量.

I would change the solution in the linked post to use a static variable rather than an instance variable, if you really only want to see the root controller being added once.

这篇关于isMovingToParentViewController 总是为导航堆栈的根视图控制器返回 FALSE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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