ios - 标签栏 UIViewController 中导航栏中的按钮未显示

标签 ios swift uiviewcontroller

我似乎无法让任何按钮出现在我的导航栏中。

流程:Navigation Controller -> Tab bar Controller -> ViewController(想把按钮放在这里)

我尝试在 ViewDidLoad 中以编程方式添加它:

let navigationBar = navigationController!.navigationBar
    navigationBar.tintColor = UIColor.blackColor()

let leftButton =  UIBarButtonItem(title: "Left Button", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
let rightButton = UIBarButtonItem(title: "Right Button", style: UIBarButtonItemStyle.Plain, target: self, action: nil)

    navigationItem.leftBarButtonItem = leftButton
    navigationItem.rightBarButtonItem = rightButton

我也尝试过使用 Storyboard添加它,但它在运行时不显示。知道为什么我不能让按钮出现在导航栏中

最佳答案

试试这样:

self.tabBarController?.navigationItem.leftBarButtonItems = [leftButton]

关于ios - 标签栏 UIViewController 中导航栏中的按钮未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747470/

相关文章:

ios - swift : Create a multi-function multicast delegate

swift - AWS SNS 直接从 iOS 发送远程通知总是报错

iOS 标签不会在 Swift 中使用函数更新文本

swift - 简单地等待来自异步线程的值

ios - 更改现有 Parse 数据的问题

ios - 兑换交易,删除 tableviewcell

ios - 无法推断通用参数 S

ios - If 语句检查 NSArray 大小

swift - 如何测试未定义的数组?

ios - 以编程方式创建的后退按钮没有箭头