Eric S
Eric S

Reputation: 21

ios NavigationBarHidden not working in viewDidLoad

Hi I am new to swift IOS programming. I am having trouble hiding the navigation bar in function viewDidLoad().

This is the code I have:

self.navigationController.navigationBarHidden = TRUE

However it is not hiding the navigation bar once the view loads. Do I need to place more code somewhere else?

UPDATE: Problem solved! Replaced the viewDidLoad() with viewWillAppear() and now it is working. Thank you everyone.

Upvotes: 0

Views: 483

Answers (3)

khoiNN
khoiNN

Reputation: 45

The viewDidLoad() method is call only once when ViewController loads. You should try to put it in viewWillAppear() or viewDidAppear() method.

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBarHidden = true
}

Upvotes: 0

Tamás Zahola
Tamás Zahola

Reputation: 9311

viewDidLoad is not the appropriate place for this, since your view controller is yet to be added to the navigation controller's stack. You should use viewWillAppear instead!

Upvotes: 0

Rahul Mayani
Rahul Mayani

Reputation: 3831

Replace that code in viewWillAppear instead of viewDidLoad, and it should work properly

override func viewWillAppear(animated: Bool) {
  super.viewWillAppear(animated)
  self.navigationController?.navigationBar.hidden = true
}

Upvotes: 3

Related Questions