iosswiftuinavigationcontrolleruitabbarcontrolleruiview-hierarchy

(Swift) Switching between UINavigationController and UITabController nested within Main UINavigationController


Through storyboard, the app entry point is a separate UINavigationController that does some logic on user authentication to first determine whether to push the Home view's embedded UITabBarController or present the Sign-In/Sign-Up view's embedded UINavigationController - this I was okay with.

The difficulty I have is how to properly make direct transitions between, back-and-forth, the Sign-In/-Sign Up view's embedded UINavigationController on sign-in/sign-up and the Home view's embedded UITabBarController on sign-out. I believe conflict lies in handling the original rootviewcontroller upon entry to push/present the aforementioned views and the "rootviewcontroller relationship" the nested UINavigationController has within the Sign-In/Sign-Up view.

I don't know how to push/present from the original rootviewcontroller for these direct transitions. If someone could help clarify, whether it's using appdelegate, etc, it'd be much appreciated!

Storyboard UI Flow


Solution

  • There's a few ways you can handle this, but generally, my go to way is to handle this simply by having one main navigation controller which will keep the entire sign in / main menu array of controllers in it, and simply add or remove the menu from view controllers depending on whether the user is logged in or logged out (show either just [signin] or [signin, mainmenu] as view controllers on navigation controller).

    Lastly, depending on what kind of logic the tab bar has, usually I'll embed a navigation controller for each tab bar item.

    Take a look at a quick sketch here: sketch