在segueing之后如何向导航控制器添加按钮? [英] How to add buttons to navigation controller visible after segueing?

查看:146
本文介绍了在segueing之后如何向导航控制器添加按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Storyboard中设置了一个嵌入导航控制器的视图控制器。在此导航控制器中,我已选中显示导航栏和显示工具栏,并在模拟指标中分别在顶栏和底栏中启用导航栏和工具栏。然后我从视图控制器显示例如推送segue到另一个视图控制器。在两个视图控制器上,我都以相同的方式设置了模拟指标,因此导航栏和工具栏在所有三个控制器上都可见。

I have set up a view controller in Storyboard which is embedded in a navigation controller. In this nav controller I have checked Shows Navigation Bar and Shows Toolbar and enabled a navigation bar and toolbar in Top Bar and Bottom Bar respectively in Simulated Metrics. I then "Show e.g. Push" segue from the view controller to another view controller. On both view controllers I've set up Simulated Metrics the same way, so both the navigation bar and toolbar are visible on all three controllers.

问题是,我可以将条形按钮项添加到导航栏和工具栏的第一个视图控制器,但我无法将条形按钮项添加到第二个视图控制器上的导航栏。当我在导航栏上放下一个按钮时,它会被添加到工具栏中。我无法双击导航栏添加标题。在大纲中,我看到第二个视图控制器上没有导航项,但它位于第一个视图控制器中。

The problem is, I can add bar button items to the first view controller to both the navigation bar and the toolbar, but I cannot add a bar button item to the navigation bar on the second view controller. When I drop a button on the navigation bar, it's added to the toolbar instead. And I cannot double click the nav bar to add a title. In the outline I see there is no navigation item on the second view controller, but it is there in the first view controller.

我可以在导航栏中添加按钮以编程方式,但我想在Storyboard中直观地进行此操作。我的问题是,这个设置有什么问题,或者这是Xcode的错误?

I can probably add buttons to the navigation bar programmatically, but I want to do this visually in Storyboard. My question is, what is wrong with this setup, or is this a bug with Xcode?

推荐答案

对于XCode 6, UINavigationItem 不会自动添加到故事板内的视图控制器对象上。在将 UIBarButtonItem 添加到其上之前,您必须将 UINavigationItem 拖到该视图Controller对象的导航栏上。

For XCode 6, the UINavigationItem for the 2nd view controller onwards is not added automatically on the View Controller Object inside the storyboard. You will have to drag the UINavigationItem onto the Navigation Bar for that view Controller Object before adding UIBarButtonItem on top of it.

我不确定为什么会这样设计。我几周前才发现这件事。

I am not sure why it is designed that way. I only discovered about this a few weeks ago.

这篇关于在segueing之后如何向导航控制器添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆