Error404 Error404 - 3 months ago 18
iOS Question

How can I hide navigation bar of a specific View Controller?

What I am trying is to set a

View Controller
(root) with a
Navigation Controller
that will connect with three
View Controller
.

Two of the linked
View Controller
have to have a
Navigation bar
on the top of each screen. The other one do not have to have the
Navigation bar
. Further, the root
View Controller
do not have to have a
Navigation bar
.

I hide the
Navigation bar
on the root
View Controller
as follows:

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

override func viewWillDisappear(animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: animated)
super.viewWillDisappear(animated)
}


but I am not able to hide the
Navigation bar
on the linked
View Controller
that does not have to have the
Navigation bar
.

I have tried on the
viewDidLoad
function of the
View Controller
in which I want to hide the
Navigation bar
using:

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


but the
Navigation bar
is still being shown.

How can I hide the
Navigation bar
on a specific
View Controller
?

Thanks in advance!

Answer

You are making mistake, in question you have set falsein viewDidLoad to hide navigationBar, you need to set true instead of false, also try on viewDidAppear.

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