Today, after hunting a nasty bug, i tracked down the order of view controllers being poped,
in case PopToRootNavigationController is called. i was pretty shocked.
Let’s say we have 3 view controllers
A (root)
B
C
if we call PopToRoot on controller C. the first controller being removed from the stack is B, only after B is removed, controller C is being removed.
I was expected the exact opposite. what the last one that was pushed is the first one the be popped.
Can someone explain why apple choose this kind of behavior?
Thanks
Say you have 100 viewcontrollers on the stack and you want to perform
so popping every view controller one by one till the last view controller is reached doesn’t make sense.. because then you are expecting it to release every object one by one and this will take time .. so what ios does is , it just pops to the last view controller and releases the 2nd view controller. So this way once 2nd is released all its subsequent child objects are also released and thus is much faster (I guess it works on heap system).
Where as when you pop it like..
this Pops view controllers until the specified view controller is at the top of the navigation stack.
hoping this clears some of the air..