简体   繁体   English

选项卡栏中的导航栏中的按钮UIViewController未显示

[英]Button in Navigation Bar in Tab Bar UIViewController not showing

I can't seem to get any buttons to appear in my navigation bar. 我似乎无法在导航栏中显示任何按钮。

Flow: Navigation Controller -> Tab bar Controller -> ViewController (want to put button here) 流程:导航控制器 - >标签栏控制器 - > ViewController(想把按钮放在这里)

I've tried adding it programmatically inside of ViewDidLoad: 我尝试在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

I've also tried adding it using the storyboard but it doesnt show during runtime. 我也尝试使用故事板添加它,但它在运行时没有显示。 Any idea why I can't get a button to appear in the navigation bar 知道为什么我无法在导航栏中显示按钮

试试这样:

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

views from storyboard or xib load after viewWillAppear method call. viewWillAppear方法调用后,来自storyboard或xib加载的视图。 and viewDidLoad method call before viewWillAppear. 和viewWillAppear之前调用viewDidLoad方法。

so navigation bar is nil during viewDidLoad method so they are not appear.so write you code in viewdidappear method and your buttons will be appeared. 所以导航栏在viewDidLoad方法中为零,因此它们不会出现。所以在viewdidappear方法中编写代码 ,你的按钮就会出现。

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

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