0
votes

Each of the view controllers presented need to present their own navigation bar title - I am programmatically creating the titles - but how can they be passed to the CBFlashyTabBarController function similar to the array of viewControllers. Currently the navigation bar controller is presenting with no titles at all.

let test1VC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Test1")

The following navigationItem.title is not presented once pushViewController is executed.

  test1VC.navigationItem.title = "Test1"
  test1VC.tabBarItem = UITabBarItem(title: "Test1", image: #imageLiteral(resourceName: "img1TabLarge"), tag: 0)
                            
let test2VC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "0")

The following navigationItem.title is not presented once pushViewController is executed.

  test1VC.navigationItem.title = "Test2"
  test1VC.tabBarItem = UITabBarItem(title: "Test2", image: #imageLiteral(resourceName: "img2TabLarge"), tag: 0)

let tabBarController = CBFlashyTabBarController()

let controllers = [test1VC, test2VC]
  tabBarController.viewControllers = controllers
                        
navigationController?.pushViewController(tabBarController, animated: true)
1
The title is a property of the viewController, not the navigationItem. You are settng it in the wrong place. - flanker
Can you please show me an example of how to assign the navigation title to each viewController? - user17235974

1 Answers

0
votes

You are not creating the UINavigationController that's why. While using TabBarController it's better to use a separate NavigationController for each tab and instead of pushing the viewController, present the tabBarController above the current VC.

let test1VC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Test1")
        
test1VC.navigationItem.title = "Test1"
test1VC.tabBarItem = UITabBarItem(title: "Test1", image: #imageLiteral(resourceName: "img1TabLarge"), tag: 0)
    
let test2VC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "0")
    
let controller1 = UINavigationController(rootViewController: test1VC)
let controller2 = UINavigationController(rootViewController: test2VC)
    
let tabBarController = CBFlashyTabBarController()

let controllers = [controller1, controller2]
    tabBarController.viewControllers = controllers
    
tabBarController.modalPresentationStyle = .fullScreen
    
self.present(tabBarController, animated: true, completion: nil)