在以编程方式呈现后,NavigationController在Swift中为零

时间:2018-06-16 18:26:31

标签: ios swift uinavigationcontroller

我以编程方式呈现UINavigationController:

let homeViewController = HomeViewController.loadFromNibNamed(nibNamed: "HomeViewController")
let homeNavigationViewController = UINavigationController(rootViewController: homeViewController!)
self.present(homeNavigationViewController, animated: true, completion: nil)

但是在HomeViewController中有一个self.navigationController!.navigationBar的调用,其中navigationController是nil?

1 个答案:

答案 0 :(得分:3)

尝试在viewWillAppear()中打印或使用self.navigationController?.navigationBar。

我认为navigationController是可选的。