Reputation: 1411
I've got a pretty simple question. In my app, there are some screens that have a navigation bar, and some that don't have it. So, what I did was to flag this manually between screen in prepareForSegue:
using this line self.navigationController?.setNavigationBarHidden(true/false, animated: false)
. Now, how do I do it if I want to go back from a view controller with a navigation bar to a view controller that doesn't have it by clicking on the back button? I tried putting it in the prepareForSegue:
of the child view controller but it doesn't work.
Thanks.
Upvotes: 0
Views: 75
Reputation: 2177
you can also use a better approach with unwind segue
override func didMoveToParentViewController(parent: UIViewController?) {
if (parent == nil) {
println("Back Button Pressed!")
}
}
Upvotes: 0
Reputation: 468
It depends how you are maintaining your flags for hiding/unhiding the navigation Bar but you can use UINavigationControllerDelegate
for the same
@available(iOS 2.0, *)
optional public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool)
@available(iOS 2.0, *)
optional public func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool)
Alternatively, you can try to put setNavigationBarHidden
in viewWillAppear
and viewWillDisappear
for each viewController.
Upvotes: 1