Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 629
Cyril Avatar asked May 21 '26 17:05

Cyril


1 Answers

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.

like image 88
Chris Goldman Avatar answered May 24 '26 07:05

Chris Goldman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!