I'm using a navigationController as the window.rootViewController . And as the rootViewController of navigationController , I'm using a tabBarController. But when I run the app, the title of the navigationBar is not showing up (My Tabbar Controller shows up and I'm being able to see my viewController. No problem about that) . I've tried to name the navigationBar in every viewController of the tabBar with using both of the code below in the viewDidload, but still nothing changed.
navigationController?.title = "title"
navigationController?.navigationBar.topItem?.title = "title"
I've set the navigationController with tabbar in the SceneDelegete as below:
let countriesTabbarController = TabBarControllerBuilder.build()
let navigationController = UINavigationController(rootViewController: countriesTabbarController)
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
How can I show my navigationController title for every viewController of the tabBar?
Each view controller has a property called navigationItem
of type UINavigationItem
. If you set its title
, it will show up in the navigation bar if one exists.
For example in viewDidLoad
, add this:
self.navigationItem.title = "title"
In other words: The title is set on the view controller contained in a navigation controller stack, not the navigation controller itself. Also not on the navigation bar, which probably also has a good reason I can't recall at the moment.
https://developer.apple.com/documentation/uikit/uinavigationitem
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.