Home > Blockchain >  Navigating within Tab Controller
Navigating within Tab Controller

Time:12-27

I am pretty new to Xcode and Swift (though plenty of experience with other languages) and am stuck on a rather trivial problem.

I set up a basic login/register page that goes into the main page of the app (a tab view controller) but I want there to be a unique navigation bar per tab. In the First Tab (Main View Controller) I want to be able to Log Out (go all the way back to the Login screen) as well as click the " " which will show a new view controller. I had this all working before adding the Tab Controller.

Now that I have the Tab Controller, the Tab Controller is overriding the navigation bar section and I am stuck with the standard "< Back" button on the navigation bar. I have tried some tricks with hiding and showing navigation bars but no luck. My First Tab (Main View Controller) now only shows the "< Back" and not the Log Out and " ".

Furthermore, once the Log Out button is showing I need to get it to go all the way back to the login screen. I attached a picture to help.

Storyboard

XCode: 14.2 Swift: 5.7

CodePudding user response:

Here's how I would setup the storyboard. Start by ignoring the need to login for a moment.

  1. Make the tab bar controller the initial view controller of your storyboard.
  2. Each tab of the tab bar controller should have its own navigation controller, if needed. In other words, a tab can either be a single view controller or it can be a stack of view controllers managed by a tab-specific navigation controller.
  3. Now add the login controller as a controller that is presented modally over the tab bar controller.

On app startup you can immediately present the login controller over the tab bar controller if the user needs to login. Once the user successfully logs in you dismiss the login controller revealing the tab bar controller.

Later on when the user chooses to logout you present the login controller modally over the tab bar controller again.

  • Related