views:

130

answers:

2

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

+1  A: 
  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.

gerry3
thank you, just what i needed to give me a start
Makinitez21
+1  A: 
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.

Alex Reynolds
thank you, exactly what i was looking for
Makinitez21