0
votes

I'm trying to use the navigation bar from the Navigation Controller while using the tab bar from the UITabBarController. If I set my Navigation Controller's root controller to my Tab Bar View Controller, I get image 2. If I set the root controller to my main View Controller (which is Tab Bar item 0), I get picture 1.

IMG:
desired navigation bar

IMG:
desired tab bar

I'm not using the storyboard, right now my hierarchy is as follows:

NavigationController->UITabBarController->ViewControllers

AppDelegate.swift:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    window?.rootViewController = UINavigationController(rootViewController: TabViewController())

    return true
}
1

1 Answers

0
votes

This is happening because if you have more than one navigationController or NavigationBar, then initial navigation bar will cover next navigationBar by default. You can achieve desired result by setting navigation bar of initial navigationController hidden

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

 window = UIWindow(frame: UIScreen.main.bounds)
 window?.makeKeyAndVisible()
 let navigation =  UINavigationController(rootViewController: TabViewController()) 
 navigation.setNavigationBarHidden(true, animated: false)
 window?.rootViewController = navigation
 return true 
}