![](/img/trans.png)
[英]How to programmatically show a controller that has a navigation controller and tabbar controller as defined in a storyboard?
[英]Navigation Controller doesn't show the title while working with TabBar Controller(Programmatically)
我使用navigationController作為window.rootViewController 。 作為navigationController的rootViewController ,我使用的是 tabBarController。 但是當我運行應用程序時,navigationBar 的標題沒有出現(我的 Tabbar Controller 出現了,我可以看到我的 viewController。沒問題) 。 我嘗試使用 viewDidload 中的以下兩個代碼在 tabBar 的每個 viewController 中命名 navigationBar,但仍然沒有任何改變。
navigationController?.title = "title"
navigationController?.navigationBar.topItem?.title = "title"
我在 SceneDelegete 中設置了帶有標簽欄的 navigationController,如下所示:
let countriesTabbarController = TabBarControllerBuilder.build()
let navigationController = UINavigationController(rootViewController: countriesTabbarController)
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
如何為 tabBar 的每個 viewController 顯示我的 navigationController 標題?
每個視圖 controller 都有一個名為navigationItem
類型為UINavigationItem
的屬性。 如果您設置它的title
,它會在導航欄中顯示(如果存在)。
例如在viewDidLoad
中,添加:
self.navigationItem.title = "title"
換句話說:標題是在導航 controller 堆棧中包含的視圖 controller 上設置的,而不是導航 controller 本身。 也沒有在導航欄上,這可能也是我現在想不起來的一個很好的理由。
https://developer.apple.com/documentation/uikit/uinavigationitem
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.