Zhen Zhen - 6 months ago 50
iOS Question

How to identify previous view controller in navigation stack

I have 2 seperate navigationcontrollers, one with RootViewController A and the other with RootViewController B.

I am able to push ViewController C onto either A or B's navigation stack.

Question: When I am in ViewController C, how can I find out if I am in the stack belonging to A or B?

Answer

You could use the UINavigationController's viewControllers property:

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

http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

You could use that to test whether the root view controller (the one at array index 0) is view controller A or B.

Comments