Subclass the UINavigationController
and implement the pushViewController:animated:
method in the subclass. There you can iterate through the stack by calling self.viewControllers
which returns an NSArray
of the view controllers on the stack. There you can check, whether the controller you're trying to push has already been pushed before. If not, call [super pushView...]
. If it has, create a mutable copy of the stack NSMutableArray * newStack = [self.viewControllers mutableCopy]
and move the desired view controller to the end of the array. Once you have that, just call [super setViewControllers:newStack animated:...]
which sets your new stack manually.
I don't think you need to override the popViewController
method, though.
Oh, and once you have that, don't forget to change the class of the UINavigationController
in the Storyboard to the name of your subclass of the navigation controller.
Another thought - if you're using the segmented control, have you thought about using UITabBarController
instead of UINavigationController
for navigation?