14

I have the following Storyboard Segue in my Swift project:

enter image description here

The animation is correct, but there is no navigation bar in the destination view controller. I want to force the destination view controller to have a navigation bar. I tried in the destination view controller:

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

Or:

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

But it refuses to show any navigation bar.

How can I perform a vertical segue (like "Cover Vertical") but still display a translucent Navigation bar in the destination view controller?

Edit: My Attributes inspector for the destination view controller:

enter image description here

Community
  • 1
  • 1
Camillo
  • 544
  • 1
  • 6
  • 24
  • 1
    Is your destination controller embedded in a navigation controller? Is your segue to the navigation controller or your view controller? – Aaron Brager Feb 09 '15 at 01:11
  • 1
    (Is `self.navigationController` `nil`?) – Aaron Brager Feb 09 '15 at 01:11
  • `println(self.navigationController)` in my destination view controller prints: `Optional()` - my original view controller is embedded in a navigation controller. – Camillo Feb 09 '15 at 01:15

1 Answers1

31

Try to create the Segue to a Navigation controller instead of your view controller. Navigation bars are only shown for view controllers in a navigation stack. In your case, the source view controller seems to be in a navigation stack but not the presented view controller. Try something like this:

enter image description here

fz.
  • 3,233
  • 22
  • 20
  • 4
    it's crazy, but it works) thanks. it's strange, I had similar structure without this intermediate navigation controller in one of my previous projects, and it works there. I mean it displays navigation bar by default – heximal Aug 29 '15 at 13:35
  • 2
    easy tip: select your modal view, Xcode Editor menu > Embedded In > Navigation Controller. :-) – Vahid Dec 20 '16 at 08:14
  • Ahh that solved it. One of those storyboard quirks – Chris Feb 21 '22 at 21:35