视图控制器中未显示任何导航栏或任何导航栏属性

时间:2018-06-25 17:43:14

标签: swift xcode uinavigationcontroller uinavigationbar

我有一个视图控制器,我想有一个带有标题和标题右侧按钮的导航栏。但是由于某些原因,导航栏没有显示。

在应用程序委托中,我添加了:

window?.rootViewController =
 UINavigationController(rootViewController: MessagesController())
 UITableViewCell.appearance().textLabel?.textColor = UIColor.white;
 UITableViewCell.appearance().backgroundColor = UIColor.clear
 UIApplication.shared.statusBarStyle = .lightContent
 UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]
 UINavigationBar.appearance().barTintColor = UIColor(red:0.13, green:0.15, blue:0.18, alpha:1.0)

 UIApplication.shared.isStatusBarHidden = false

在视图控制器的viewDidLoad中,我想要导航栏,这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    let dummyViewController = UIViewController()
    dummyViewController.view.backgroundColor = .white
    dummyViewController.navigationItem.title = "TEST"
    navigationController?.navigationBar.tintColor = .white

为什么没有导航栏,为什么不能向其中添加带有按钮的标题?欢迎任何帮助,谢谢。

1 个答案:

答案 0 :(得分:3)

我曾经遇到过一个暗UINavigationBar的问题。尝试在您的viewDidLoad中添加此行:

self.navigationController?.navigationBar.barStyle = .black

这为我解决了这个问题。让我知道是否有帮助。