我一直在与UINavigationController斗争很多小时,因为它拒绝显示任何标题,甚至拒绝显示titleView,BackItem?。标题,一切都不起作用。我可以看到顶部的导航栏,只是空白。这是我的代码:
class tab1_main: UIViewController {
var main_nav_controller = UINavigationController()
override func viewDidLoad() {
main_nav_controller.navigationBar.backItem?.title = "Hello" //NO LUCK
main_nav_controller.navigationBar.topItem?.title = "Hello" //NO LUCK
main_nav_controller.title = "Hello" //NO LUCK
self.title = "Hello" //NO LUCK
navigationItem.title = "Hello" //NO LUCK
view.addSubview(main_nav_controller.view)
tab1_startup()
}
}
tab1_main viewController 放在导航控制器视图堆栈的底部,而不是在tab1_main视图控制器中创建导航控制器。
let tab1_main = UIViewController()
let main_nav_controller = UINavigationController(rootViewController: tab1_main)
你来了。 :)我希望它有所帮助。
// Set up the title
self.navigationItem.title = "Title"
/// if you want to use large title then set true to use large title into small title if scroll down.
self.navigationController?.navigationBar.prefersLargeTitles = true