PersianBlue PersianBlue - 3 months ago 6
Swift Question

How to get rid of the navigation bar for one screen and show for the remaining

I want to hide the navigation bar for the first view controller and show for the rest. In order to achieve this I wrote the following code :

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

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


After writing this code it works fine, i.e this view controller does not show the navigation bar and the rest show as desired. But after writing this code another problem arise which is as follows:
problem link.

According to the solution given on the above link I need to remove the code:

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


Which brings me back to problem 1
Can anybody help to get rid of both issues?

Answer

Use this instead of navigationBarHidden:

self.navigationController?.setNavigationBarHidden(true, animated: animated)
Comments