I am using storyboards in my iOS. The first screen is the login screen. When a user logs out or gets logged out, he may be on a screen in a deep hierarchy.
For example: login view controller => modal view controller => tab bar controller => nav controller => view controller => view controller. I want to go all the way back from the top-most view controller to the bottom one.
Edit: Here's a diagram of the view hierarchy:
Thanks!
I wrote a category for UIViewControllers that seems to be working:
- (void) popToInitialViewController
{
UIViewController *vc;
if (self.navigationController != nil) {
vc = self.navigationController;
[self.navigationController popToRootViewControllerAnimated:NO];
[vc popToInitialViewController];
}
else if (self.tabBarController != nil) {
vc = self.tabBarController;
[vc popToInitialViewController];
}
else if (self.presentingViewController != nil) {
vc = self;
while (vc.presentingViewController != nil)
vc = vc.presentingViewController;
[vc dismissModalViewControllerAnimated:NO];
[vc popToInitialViewController];
}
}
Comments are appreciated :)
this should work assuming everything was pushed onto the navigation stack:
[self.navigationController popToRootViewControllerAnimated:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With