简体   繁体   English

无法将条形按钮项添加到Xcode中的导航控制器

[英]Cannot add Bar Button Item to Navigation Controller in Xcode

I am building a todo list app to get more practice with tableViews and delegates. 我正在构建一个待办事项列表应用程序,以便使用tableViews和delegates进行更多练习。 I have embedded my primary tableViewController in a Navigation Controller and I have created two additional view controllers, one for adding a task and one fore editing a task. 我已将我的主tableViewController嵌入到导航控制器中,并且我创建了两个额外的视图控制器,一个用于添加任务,另一个用于编辑任务。 When I attempt to add a bar button item to one of the additional view controllers (done, trash, etc), Xcode is placing the item in a tab bar along the bottom of the screen and when I run the app, those items are not visible. 当我尝试将一个条形按钮项添加到其中一个附加视图控制器(完成,垃圾等)时,Xcode将项目放在屏幕底部的标签栏中,当我运行应用程序时,这些项目不是可见。 I have changed the type of device I am working on, relaunched Xcode entirely, and I cannot figure out why this is happening. 我已经改变了我正在使用的设备类型,完全重新启动了Xcode,我无法弄清楚为什么会发生这种情况。 I have added a screenshot below and here is a link to the repo. 我在下面添加了一个截图, 这里是一个回购链接。 Any ideas why this is happening? 任何想法为什么会这样?

在此输入图像描述

first you need to add Navigation Item in Navigation Bar. 首先,您需要在导航栏中添加导航项 then add UIBarButton in Navigation Item. 然后在导航项中添加UIBarButton。

导航项目

完整的例子

Programatically you can add as: 以编程方式,您可以添加为:

        let shareBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.shareClass))

        let downloadBarButtonItem = UIBarButtonItem(image: UIImage(string: UIImage(named: "your_image_name")), style: .plain, target: self, action: #selector(self.downloadClass))

        self.navigationItem.setRightBarButtonItems([shareBarButtonItem, downloadBarButtonItem], animated: true)

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

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