Makinitez21
Makinitez21

Reputation: 89

Monitoring UINavigation stack

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

Answers (2)

Alex Reynolds
Alex Reynolds

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

gerry3
gerry3

Reputation: 21460

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

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

Related Questions