3

I'm trying to display the navigation bar at the top of the screen, but it's not showing in embed navigation controller.

Here is how it is in the storyboard: enter image description here

And here it's in the simulator:

enter image description here

As you can see, I created a custom TabBar (following this tutorial) at the bottom of the screen so I can navigate between the different views.

I believe that I'm going to have to load the navbar programatically because the only solution that I found was to set the navigation controller as the initial view controller, but I already set another view as the initial one so I can't do that.

Alexandre Lara
  • 2,464
  • 1
  • 28
  • 35
  • Possible duplicate of [Swift 3 - Why is my Navigation Bar not showing?](https://stackoverflow.com/questions/45407806/swift-3-why-is-my-navigation-bar-not-showing) – Mujahid Latif Mar 26 '18 at 10:04

3 Answers3

3

Issue :

When you instantiate a viewController using storyBoard identifier they wont come with free embedded navigation controller, even if you have added a NavigationController to them. As a result you are adding a viewController without navigation bar to your tab bar VC.

Solutions:

Solution1: If you want each child viewControllers to carry their own navigation controller hence their own navigation stack, provide a storyboard identifier to Navigation Controller behind your child viewControllers and instantiate the Navigation controller itself rather than ViewController. And add NavigationController as you tab bar looking VC's child. Because navigation controller loads the embdedded VC by default you will see your child VC with nav bar.

Solution2: All that you care for is only nav bar than add the Navigation Controller behind the VC containing tab bar looking View.

Hope it helps

Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78
  • The first solution was my choice because there are some views that I don't want to have the navbar at the top, so I believe that I would have to do an extra job to hide the navbar or change some attributes of it. – Alexandre Lara Feb 16 '17 at 03:05
  • @alexandre-lara : Glad to know that your problem solved :) Happy coding – Sandeep Bhandari Feb 16 '17 at 05:31
  • @SandeepBhandari where do i instantiate Navigation controller itself ? Thanks. – jorge saraiva Nov 27 '17 at 02:34
  • @jorge-saraiva : Sorry not really sure If I understand u correct, but if you want to instantiate navigation controller from storyboard as I suggested in my solution 1 you can add a storyboard identifier to Navigation Controller itself and then you can instantiate it in your code. But usually if a NaviagtionController has a associated ViewController as its initialView Controller in storyboard even that ViewController will be instantiated :) – Sandeep Bhandari Nov 27 '17 at 06:32
0

Have you tried constraining the navigation bar to your view? Otherwise it can move offscreen.

Natasha
  • 54
  • 6
0

You need to point the tab bar controller segue to the navigation controller of your view - otherwise if you point the segue straight to the view you're just loading the view without any navigation controller attached.

Trev14
  • 3,626
  • 2
  • 31
  • 40