簡體   English   中英

選項卡欄中的導航欄中的按鈕UIViewController未顯示

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

我似乎無法在導航欄中顯示任何按鈕。

流程:導航控制器 - >標簽欄控制器 - > 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

我也嘗試使用故事板添加它,但它在運行時沒有顯示。 知道為什么我無法在導航欄中顯示按鈕

試試這樣:

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

viewWillAppear方法調用后,來自storyboard或xib加載的視圖。 和viewWillAppear之前調用viewDidLoad方法。

所以導航欄在viewDidLoad方法中為零,因此它們不會出現。所以在viewdidappear方法中編寫代碼 ,你的按鈕就會出現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM