[英]Navigation Controller doesn't show the title while working with TabBar Controller(Programmatically)
I'm using a navigationController as the window.rootViewController .我使用navigationController作为window.rootViewController 。 And as the rootViewController of navigationController , I'm using a tabBarController.
作为navigationController的rootViewController ,我使用的是 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) .
但是当我运行应用程序时,navigationBar 的标题没有出现(我的 Tabbar Controller 出现了,我可以看到我的 viewController。没问题) 。 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.
我尝试使用 viewDidload 中的以下两个代码在 tabBar 的每个 viewController 中命名 navigationBar,但仍然没有任何改变。
navigationController?.title = "title"
navigationController?.navigationBar.topItem?.title = "title"
I've set the navigationController with tabbar in the SceneDelegete as below:我在 SceneDelegete 中设置了带有标签栏的 navigationController,如下所示:
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?如何为 tabBar 的每个 viewController 显示我的 navigationController 标题?
Each view controller has a property called navigationItem
of type UINavigationItem
.每个视图 controller 都有一个名为
navigationItem
类型为UINavigationItem
的属性。 If you set its title
, it will show up in the navigation bar if one exists.如果您设置它的
title
,它会在导航栏中显示(如果存在)。
For example in viewDidLoad
, add this:例如在
viewDidLoad
中,添加:
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.换句话说:标题是在导航 controller 堆栈中包含的视图 controller 上设置的,而不是导航 controller 本身。 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 https://developer.apple.com/documentation/uikit/uinavigationitem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.