I need to identify what UIViewController
was previously shown in a UINavigationController
. My navigation is 3 levels deep, in level 2 I need to identify if I got here from pushing from level 1 or if I got here from popping from level 3. How can I do this easily?
Implement the UINavigationControllerDelegate method:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
and query it to find out the currently displayed view controller:
navigationController.topViewController
This is the one you're coming from.
You can look at the entire UINavigationController stack by using the the viewControllers property.
int count = [navigationController.viewControllers count];
topController = [navigationController.viewControllers objectAtIndex:count - 1];
previousController = [navigationController.viewControllers objectAtIndex:count - 2];
//...
//...
rootController = [navigationController.viewControllers objectAtIndex: count - count];
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