I just wrote this piece of code for the project I’m currently working on.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
-(void)gotoSpecificController{ NSArray *viewControllers = self.navigationController.viewControllers; NSInteger index = viewControllers.count - 1; while (YES) { index--; UIViewController *vc = [viewControllers objectAtIndex:index]; if([vc isKindOfClass:[SpecificController class]]){ [self.navigationController popToViewController:vc animated:YES]; return; } } } |
You can use it if you know for sure that view controller of SpecificController class exists somewhere in the Navigation stack. Otherwise your app will crush when index goes down to -1.