Michael
Michael

Reputation: 1144

NavigationController is nil in Swift after Presenting Programmatically

I am presenting a UINavigationController programmatically like this:

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

but then in HomeViewController there is a call for self.navigationController!.navigationBar where the navigationController is nil?

Upvotes: 0

Views: 613

Answers (1)

Aaina Jain
Aaina Jain

Reputation: 353

Try to print or use self.navigationController?.navigationBar in viewWillAppear().

I think navigationController will be optional.

Upvotes: 4

Related Questions