If you subclass your navigation controller, you can implement the popViewControllerAnimated: method and throw out isKindOfClass: check there to see if the view controller you are looking for is displayed. For instance:
- (UIViewController *)popViewControllerAnimated:(BOOL)animated { //Reference current controller being displayed UIViewController *currentController = [self.viewControllers lastObject]; //Check class if ([currentController isKindOfClass:[MyDesiredController class]]) { NSLog(@"Popping Desired Controller, Do Stuff Here"); } return [super popViewControllerAnimated:animated]; }
However, this does not cancel the actual sliding of the view controller (returning nil will cause the controller to fail, but it will still cause the navigation panel to display its information and return NO to the shouldPop: delegate method in the navigation panel. Still expose the controller independently. I heard that this only happens when using the navigation controller, but I have not tested this).
For your situation, however, since you want to open the two view controllers again, you could remove the second last view controller from the navigation controller's view controller property, converting the view controllers to nsmutablearray, removing the controller and then converting that nsmutablearray back to the array and setting it as Property for controlling the viewing of the navigation controller. I have not tested this, but I thought I would share this idea.
source share