I found the solution on @Chrizzz's answer to another question.
Basically you need two subclasses of UINavigationController
, one for master and one for detail.
In both subclasses, you must include UINavigationBarDelegate
and set the delegate to self
. Then include the following method:
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
[[[[self splitViewController] viewControllers][0 or 1] navigationController] performSelector:@selector(popViewControllerAnimated:) withObject:@YES afterDelay:0];
return YES;
}
In the master, you'll want to pop the detail VC, so put a 1
on the index.
In the detail, you'll want to pop the master VC, so put a 0
on the index.
This solution allows you to run a routine before popping the view controller.
Update
I was getting some NavigationBar errors getting corrupted such as nested pop animation can result in corrupted navigation bar
. So instead of directly calling popViewControllerAnimated:
I called performSelector:
with zero delay and nothing bad happens now when I pop my views.