Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the stack in UINavigationController

Tags:

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?

like image 216
Dheeraj Kaveti Avatar asked Jun 27 '11 19:06

Dheeraj Kaveti


People also ask

How do I work with uinavigationcontroller?

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.

How to access the root view controller in uinavigationcontroller?

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.

What is the navigation stack in Salesforce?

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.

How to access the navigation controller's array of view controllers?

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.


1 Answers

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'.

like image 98
Convolution Avatar answered Sep 19 '22 15:09

Convolution