I have a come across a piece of code to pop to a specific viewcontroller in a navigation stack as below
for (UIViewController* viewController in self.navigationC
- (void) RetunToSpecificViewController{
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[AnOldViewController class]]) {
//Do not forget to import AnOldViewController.h
[self.navigationController popToViewController:controller
animated:YES];
break;
}
}
On Swift
func RetunToSpecificViewController()
{
let viewControllers: [UIViewController] = self.navigationController!.viewControllers as [UIViewController]
self.navigationController!.popToViewController(viewControllers[viewControllers.count
- 5], animated: true)
}
We have write a better tutorial on that , You can check https://appengineer.in/2014/03/13/pop-to-specific-view-controller-in-ios/