Reputation: 11340
I have the following situation: I begin with a login screen (which I want to have no toolbars or tab bars.) After the user has logged in, I want to display a tab bar with multiple options each of which can drill down into their own view hierarchy. Thus it is necessary for each of these tabs to have navigation controller capabilities.
Thus, the most immediate solution would be to have a tab bar controller and then have each section (3 in total) have their own navigation controller. However, the issue is that I want each page in the entire app to have a logout button which will bring them back to the very first screen.
I could have segues from every page's logout button back to the beginning but this seems wrong. I could also put the tab bar controller inside the navigation controller; however I've heard that navigation controllers should always be inside tab bar controllers and never the other way around.
Any suggestions
Upvotes: 1
Views: 367
Reputation: 17958
Present your "login" screen as a modal view controller on top of your tab bar controller of navigation controllers. Anytime you logout from anywhere in the app you present a new modal login view and can then reset the state of your other controllers while they are no longer visible. On login you dismiss the modal and reveal the tab bar controller and whatever it contains.
Upvotes: 1
Reputation: 6276
If the root view controller for each UINavigationController is the login screen, why not just make a logout button assigned to self.navigationItem.rightBarButtonItem
for each appropriate view. When clicked, it can call your logout function and then popToRootViewControllerAnimated:
to take you back to the login screen.
You can use setNavigationBarHidden:animated:
in any view you want or don't want the navigation bar to be shown.
Upvotes: 2