viewControllers
The view controllers currently on the navigation stack.
@property(nonatomic, copy) NSArray * viewControllers
Discussion
The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.
Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.
I am confused how to access the the stack I have three views in the navigation controller – root view controller, sti testing location, sti map.
How can I access the stack?
The UINavigationController class is easy to work with. A navigation controller is an example of view controller containment. Every navigation controller manages a stack of view controllers. View controllers can be pushed onto the navigation stack or popped from the navigation stack.
You can access the top view controller through the topViewController computed property, but the UINavigationController class doesn't offer an API that easily lets you access the root controller. But it's easy to do. The root view controller is simply the view controller that sits at the bottom of the navigation stack.
A navigation controller object manages its child view controllers using an ordered array, known as the navigation stack. The first view controller in the array is the root view controller and represents the bottom of the stack.
You can access the navigation controller's array of view controllers through its viewControllers property. To access the root view controller, we ask for the first item of the array of view controllers. Each view controller in the array is a child view controller and the navigation controller is the parent view controller.
UINavigationControllers
have a property called viewControllers
as you have stated above. Since this is an array of View Controllers, referencing a specific view controller in this hierarchy is no different than accessing any other object in an array.
UIViewController *theControllerYouWant = [self.navigationController.viewControllers objectAtIndex:(theIndexOfYourViewController)];
In addition check out the Navigation Controllers article in the iOS Developer Library, specifically the section called 'Modifying the Navigation Stack'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With