Returning to the original ViewController storyboard upon logout

I use storyboards in my iOS. The first screen is the login screen. When a user logs out or logs out, he may be in a deep hierarchy on the screen.

For example: login view controller => modal view controller => tab bar controller => nav controller => view controller => view controller. I want to go all the way from the top-level controller to the bottom.

Edit: Here is a view hierarchy diagram: enter image description here

Thanks!

+6
source share
2 answers

I wrote a category for UIViewControllers that seems to work:

- (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 appreciated :)

+5
source

this should work if everything is pushed to the navigation stack:

 [self.navigationController popToRootViewControllerAnimated:YES]; 
+2
source

All Articles