[英]Add UIBarButtonItem in Interface Builder to navigated UIViewController?
I have a UINavigationController
in Interface Builder in a storyboard. 我在情节
UINavigationController
中的Interface Builder中有一个UINavigationController
。 I've added two UIBarButtonItems
to the first UIViewController
. 我在第一个
UIViewController
添加了两个UIBarButtonItems
。 They display just fine. 它们显示得很好。 How can I add them to the second
UIViewController
which is navigatated to? 如何将它们添加到导航到的第二个
UIViewController
中? On that view controller, I only see the Back button. 在该视图控制器上,我仅看到“后退”按钮。
When I try dragging a UIBarButtonItem
to the top of the second view controller, the button ends up at the bottom of the scene for some reason. 当我尝试将
UIBarButtonItem
拖动到第二个视图控制器的顶部时,由于某种原因,该按钮最终在场景的底部结束。 It is not displayed when running the app. 运行应用程序时不显示。
Edit: I should have mentioned that I know how to do this in code, but not in Interface Builder. 编辑:我应该提到我知道如何在代码中执行此操作,但是在Interface Builder中却不行。
To add further informations about my comments concerning navigation item : 要添加有关我对导航项目的评论的更多信息:
Here is a simple project with a UIViewController
embedded in a UINavigationController
. 这是一个简单的项目,其中的
UIViewController
嵌入在UINavigationController
。 A second UIViewController
can be pushed via the Next button. 可以通过“下一步”按钮来推送第二个
UIViewController
。 If you select the next button, you can see in the hierarchy that this button is embedded within the group Right Bar Buttons Items
, which is embedded within the First
object. 如果选择下一个按钮,则可以在层次结构中看到此按钮嵌入在
Right Bar Buttons Items
Object Right Bar Buttons Items
组中,该组嵌入在First
对象中。 In fact, First
is a UINavigationItem
automatically added to your view controller when it was embedded in the navigation controller. 实际上,
First
是一个UINavigationItem
,当它嵌入到导航控制器中时会自动添加到视图控制器中。
But the second view controller (the pushed one) doesn't have this navigation item since it isn't directly embedded within a navigation controller. 但是第二个视图控制器(被推动的一个)没有此导航项,因为它没有直接嵌入在导航控制器中。 Simply drag and drop it from the Object Library to your view controller.
只需将其从对象库拖放到视图控制器即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.