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.
![Share on Facebook Facebook](https://successfulcoder.com/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/facebook.png)
![Share on Twitter twitter](https://successfulcoder.com/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/twitter.png)
![Share on Reddit reddit](https://successfulcoder.com/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/reddit.png)
![Pin it with Pinterest pinterest](https://successfulcoder.com/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/pinterest.png)
![Share on Linkedin linkedin](https://successfulcoder.com/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/linkedin.png)
![Share by email mail](https://successfulcoder.com/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/mail.png)