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?
The root view controller is simply the view controller that sits at the bottom of the navigation 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.
The view renders presentation of the model in a particular format. The controller responds to the user input and performs interactions on the data model objects. The controller receives the input, optionally validates it and then passes the input to the model.
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.
https://developer.apple.com/documentation/uikit/uinavigationcontroller
You could use that to test whether the root view controller (the one at array index 0) is view controller A or B.
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