Search code examples
iosuinavigationcontrolleruinavigationbaruinavigationitemuitabcontroller

How to use custom NavigationBar in ios TabBarController


I'm using a TabController which has a Navigation Controller as it's root and all works fine thus far except i would like to show the NavigationBar of the child viewcontrollers within the tab bar but for now just the tabcontroller's Navigation Bar shows.

This is how the tab bar shows now. with It's NavBar

This is the TabBar's header

This is the Navbar of the child ViewController I want to show

This is the Navbar of the child ViewController which i want to show


Solution

  • Embed a UINavigationController for each tab bar item rather than a UIViewController. You can then make the root view controller of each UINavigationController point to the view controller you want to use for that tab.

    enter image description here

    This allows each tab to have its own navigation bar and navigation stack.

    EDIT

    Also, if you intend on keeping your current navigation controller as the initial view controller, make sure you hide it's navigation bar by unselecting "Shows Navigation Bar" in interface builder

    enter image description here

    or by setting it in UITabBarController:

    self.navigationController?navigationBar.isHidden = true
    

    or by setting it in UINavigationController:

    self.navigationBar.isHidden = true