isMovingToParentViewController always returning FALSE for root view controller of a navigation stack?

匿名 (未验证) 提交于 2019-12-03 09:05:37

问题:

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?

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.

Thanks for helping.

回答1:

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

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.

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!