I am working on an iOS Navigation controller app and got a doubt. I couldn’t find it anywhere. When i create navigation controller and use multiple other view controllers to have navigation, how these view controllers are exactly stored in memory and navigation controller could able to navigate to the previous controller when we click back button etc. Could someone please explain me?
Thank you.
The concept is simple as a stack. You push an object and u can pop it too.
when you use
it pushes the object (viewController here) to the stack of viewControllers which u can access using
[navigationController viewControllers];u can check the existing controllers :
NSLog("view controllers %@", [navigationController viewControllers]);viewControllers is an NSArray having all the objects pushed into it. so the reference to a particular controller is always there and thus u can navigate back to any viewcontroller
clicking on back button pops the
topViewControllerout of the array.popToRootViewControllerpops u to the first controller added in the viewController array.u can also pop back to a specific controller in the array using
u need to pass the parameter from the NSArray(viewControllers) mentioned already eg:
hope it helps. happy coding 🙂