【问题标题】:Cannot add Bar Button Item to Navigation Controller in Xcode无法在 Xcode 中将条形按钮项添加到导航控制器
【发布时间】:2018-06-29 12:19:35
【问题描述】:

我正在构建一个待办事项列表应用程序来获得更多关于 tableView 和委托的练习。我已将我的主 tableViewController 嵌入到导航控制器中,并创建了两个额外的视图控制器,一个用于添加任务,一个用于编辑任务。当我尝试将条形按钮项添加到其他视图控制器之一(完成、垃圾等)时,Xcode 将该项放置在屏幕底部的选项卡栏中,当我运行应用程序时,这些项不是可见的。我已经更改了我正在使用的设备类型,完全重新启动了 Xcode,但我无法弄清楚为什么会发生这种情况。我在下面添加了一个屏幕截图,here 是一个指向 repo 的链接。任何想法为什么会发生这种情况?

【问题讨论】:

    标签: ios xcode uinavigationcontroller uibarbuttonitem


    【解决方案1】:

    首先您需要在导航栏中添加导航项。然后在导航项中添加 UIBarButton。

    【讨论】:

    • 你拯救了我的一天(Y)
    【解决方案2】:

    您可以通过编程方式添加为:

            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)
    

    【讨论】:

      猜你喜欢
      • 2018-06-01
      • 1970-01-01
      • 2014-04-30
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多