Search code examples
iosuitabbarcontrolleruitabbar

Tab bar controller inside a navigation controller, how to push new viewcontrollers to the tabcontroller?


Design requirement:

  1. Show a list of items the user can pick from
  2. After having picked an item, bring the user to a new view with a back button. The new view should contain a list of tabs at the bottom that are not present in the first screen
  3. When clicking an item in the tabs, a new screen should appear with a back button and the tabs should still be visible at the bottom.
  4. Clicking a tab should take the user back up the hierarchy to #2. Not to the first screen.

I have tried following structure:

and also

  • UINavigationController
  • UIViewController with a UITableView
  • UITabbarController

Both cases work fine with displaying the UITabBar, but when I click an item in one of the tabs and push a new UIViewController, then the tabs at the bottom disappears. I want the tabs to remain in place for all pushed UIViewControllers that occurs inside a tab of the UITabBarController.

A related question is this one but it doesn't deal with the problem of pushed viewcontrollers inside a tab: Tab bar controller inside a navigation controller, or sharing a navigation root view

Do I need to change the rootcontroller to the UITabController? Anyone actually implemented this?


Solution

  • Here is the correct structure:

    UITabBarcontroller (UIWindow's rootViewController)
    ->UINavigationController (first tab)
    -->UIViewController
    ->UINavigationController (second tab)
    -->UIViewController