简体   繁体   English

如何使用情节提要在消失的导航栏上添加栏按钮项?

[英]How to Add a Bar Button Item on a Disappeared Navigation Bar using Storyboard?

I want to add a bar button item on the navigation bar. 我想在导航栏上添加一个栏按钮项。 (Say View 1 here.) The view that will segue to View 1 is embedded in a navigation controller. (在这里说“视图1”。)将与视图1相连的视图嵌入在导航控制器中。

However, the navigation bar is not showing in this view. 但是,导航栏未在此视图中显示。

If I use attribute inspector to add a opaque/ translucent navigation bar, there will be a navigation bar in View 1. But if I drag in a bar button item, it cannot be shown in the storyboard. 如果我使用属性检查器添加不透明/半透明的导航栏,则视图1中将有一个导航栏。但是,如果我拖动一个栏按钮项,则它不会显示在情节提要中。 Though the bar button is in the document outline, it cannot be shown on the storyboard. 尽管条形按钮在文档大纲中,但无法在情节提要板上显示。 Also, if I run the application, it is not on the screen. 另外,如果我运行该应用程序,则它不在屏幕上。

When running the application in the simulator, View 1 will have a navigation bar on the top of it, since I use "Show" rather than "Show Details" to show View 1. I tried to embed View 1 in a navigation controller again, but it won't help much. 在模拟器中运行应用程序时,由于我使用“显示”而不是“显示详细信息”来显示视图1,因此视图1顶部会显示一个导航栏。我试图将视图1再次嵌入导航控制器中,但这没有太大帮助。

Can anyone tell me how to add a bar button in this situation using storyboard ? 谁能告诉我在这种情况下如何使用情节提要添加条形按钮? And why the navigation bar is missing from the storyboard? 以及为什么情节提要中缺少导航栏?

Thanks in advance. 提前致谢。

I figure it out by myself. 我自己弄清楚。

Drag a Navigation Item from the object list, and then add bar button item to it. 从对象列表中拖动一个导航项,然后向其添加栏按钮项。

Thanks to rdelmar for his idea, though drag out a navigation bar won't work in the way I thought it should work. 感谢rdelmar的想法,尽管将导航栏拖出不会像我认为的那样起作用。

In my situation, View 1 is a table view. 在我的情况下,视图1是一个表视图。 Drag a navigation bar to the view will cause it to be the header view for the table, rather than a navigation bar I had expected. 将导航栏拖到该视图将使它成为表的标题视图,而不是我期望的导航栏。 Then there will be two navigation bar in the view when I run the application. 当我运行应用程序时,视图中将有两个导航栏。

Of course we can drag out a navigation bar and add a button to it, it might work different with your expectation. 当然,我们可以拖出一个导航栏并向其中添加一个按钮,这可能与您的期望有所不同。 As I had said, it might leads to a view which contains two navigation bars. 如我所说,它可能会导致包含两个导航栏的视图。

You can fix this by drag out the Navigation Item (contains the bar button you had added) inside the Navigation Bar out. 您可以通过拖出“导航栏”内的“导航项”(包含您添加的栏按钮)来解决此问题。 In my situation, I drag it out and put it the same level with the table view inside the document outline. 在我的情况下,我将其拖出并与文档大纲中的表格视图放置在同一级别。 Then it won't become the header view for the table view. 这样就不会成为表格视图的标题视图。

After that, we can just delete the navigation bar from the document outline. 之后,我们只需从文档大纲中删除导航栏即可。

I have no idea why the navigation bar disappears in my storyboard. 我不知道为什么导航栏在我的情节提要中消失了。 If anyone has some idea for this, please let me know. 如果有人对此有任何想法,请告诉我。

It sounds like you're adding the navigation bar by using the Simulated Metrics. 听起来您正在通过使用“模拟量度”添加导航栏。 If so, this doesn't add one at run time, it's only for layout purposes in IB. 如果是这样,这不会在运行时添加一个,仅用于IB中的布局目的。 You should drag out a navigation bar from the objects list, and add your button to it. 您应该从对象列表中拖出一个导航栏,然后向其中添加按钮。

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

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