If you subclass your navigation controller, you can implement the popViewControllerAnimated: method, and throw an isKindOfClass: check in there to determine if the view controller you're looking for is being popped. Eg:
- (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 popping of the view controller (returning nil will stop the controller from popping but will still cause the navigation bar to pop it's information, and returning NO to the shouldPop: delegate method of the navigation bar will still pop the controller regardless. I have heard that this only occurs when using a Navigation Controller, but I haven't tested this).
For your situation however, since you desire to pop two view controllers back, you could possibly remove the second last view controller from the navigation controller's viewcontrollers property by converting the viewcontrollers to an nsmutablearray, removing the controller, and then converting this nsmutablearray back to an array and setting it as the navigation controller's viewcontrollers property. I haven't tested this but I thought I would share the idea.