Reputation: 89
Is there a way to monitor what view controller the navigation controller had before it pushed on the current view controller. also the opposite, what view controller it popped off the stack before getting to the current view controller?
Thank you in advance
Upvotes: 0
Views: 302
Reputation: 96994
NSArray *viewControllerArray = [self.navigationController viewControllers];
NSUInteger parentViewControllerIndex = [viewControllerArray count] - 2;
NSLog(@"Parent view controller: %@", [viewControllerArray objectAtIndex:parentViewControllerIndex]);
This should be enough to set a property that keeps track of properties of the last popped view controller.
Upvotes: 1
Reputation: 21460
For the view controller that was on top before a new one was pushed, you can check the object at index n-2 in the viewControllers property of the navigation controller
For the view controller that was popped, I think you would have to keep track of that yourself. You could use a static variable or a singleton.
Upvotes: 1