Last active
August 29, 2015 14:16
-
-
Save serhatsezer/e4be0d635aa278a5ca51 to your computer and use it in GitHub Desktop.
Pop to specific ViewController in NavigationController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Navigation Stack -> (pushed) | |
// Steps 1. AViewController -> 2. BViewController -> 3. CViewController | |
// in the CViewController user tapped button -> -backToFirstViewController | |
// backToFirstViewController | |
- (void)backToFirstViewController { | |
// get navigation stack as an array. | |
NSArray *viewControllers = self.navigationController.viewControllers; | |
// First way | |
// This way array goes back twice and find AViewController. This is obvious. | |
[self.navigationController popToViewController:viewControllers[viewControllers.count-2] animated:YES]; | |
// Second way | |
for(UIViewController *currentVC in viewControllers) { | |
if([currentVC isKindOfClass:[AViewController class]]) { | |
[self.navigationController popToViewController:currentVC animated:YES]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment