问题
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.
来源:https://stackoverflow.com/questions/22777796/ismovingtoparentviewcontroller-always-returning-false-for-root-view-controller-o