简体   繁体   English

导航栏未显示在嵌入式Navigation Controller中

[英]Navigation Bar not showing in embed Navigation Controller

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: 这是情节提要中的样子: 在此处输入图片说明

And here it's in the simulator: 这是在模拟器中:

在此处输入图片说明

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. 如您所见,我在屏幕底部创建了一个自定义的TabBar(在本教程之后 ),以便可以在不同的视图之间导航。

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. 我认为我将必须以编程方式加载导航栏,因为我发现的唯一解决方案是将导航控制器设置为初始视图控制器,但是我已经将另一个视图设置为初始视图控制器,因此我无法做到这一点。

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. 当您使用storyBoard标识符实例化viewController时,即使您已向其中添加NavigationController,它们也不会附带免费的嵌入式导航控制器。 As a result you are adding a viewController without navigation bar to your tab bar VC. 结果,您将不带导航栏的viewController添加到选项卡栏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. 解决方案1:如果希望每个子viewController都携带自己的导航控制器,因此也要拥有自己的导航堆栈,请向子viewController后面的导航控制器提供一个情节提要标识符,并实例化导航控制器本身而不是ViewController。 And add NavigationController as you tab bar looking VC's child. 并在选择VC子级的标签栏时添加NavigationController。 Because navigation controller loads the embdedded VC by default you will see your child VC with nav bar. 由于导航控制器默认情况下会加载嵌入式VC,因此您将看到带有导航栏的子VC。

Solution2: All that you care for is only nav bar than add the Navigation Controller behind the VC containing tab bar looking View. 解决方案2:您所关心的只是导航栏,而不是在包含“查看”的VC的选项卡栏后面添加导航控制器。

Hope it helps 希望能帮助到你

Have you tried constraining the navigation bar to your view? 您是否尝试过将导航栏限制在视图范围内? Otherwise it can move offscreen. 否则它可以移出屏幕。

您需要将标签栏控制器设置为视图的导航控制器-否则,如果将设置直接指向视图,则只是在加载视图时未连接任何导航控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM