Note. If you have a tab bar controller with navigation controllers at the root of each view controller, setting the tab bar item on the view controllers will not affect the title if you set navigationItem.title . You will need to install tabBarItem on the navigation controller instead, so that it is taken from the controller of the tab bar.
None of the answers posted by others worked for me, because all my tab bar view controllers have navigation controllers at their root - this is a common hierarchy template for UITabBarController . tabBarItem this, you must install the tabBarItem navigation tabBarItem so that the title displays differently than the navigationItem title
You can create your tabBarItem and link them to your VC directly, like this.
let tabBarVCOne = BooksListViewController() tabBarVCOne.tabBarItem = UITabBarItem(title: "Books", image: nil, tag: 0) tabBarViewControllers.append(tabBarVCOne) ...
Then you will have something like this:
But this should be changed to the following so that the tabBarItem already connected tabBarItem from the view controller and automatically set it to the navigation controller.
self.viewControllers = tabBarViewControllers.map({ let navigationController = UINavigationController(rootViewController: $0) navigationController.tabBarItem = $0.tabBarItem return navigationController })
Now you can have a different header (set from your VC) separate from the header defined for your tabBarItem .
Pavan Feb 10 '18 at 1:51 2018-02-10 01:51
source share