iOS 8 Swift navigation bar title, buttons not showing in tab based application

前端 未结 3 2216
长情又很酷
长情又很酷 2021-02-10 11:34

I am trying to follow this tutorial, this answer, and this answer to create navigation bars for each of my tabs in a tab-based application in iOS 8 / Swift, but no title or butt

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-10 11:51

    You're making a custom UINavigationBar when one is already provided to you with the UINavigationController.

    Try this instead in your ViewController:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        self.title = "Title"
    
        let navigationBar = navigationController!.navigationBar
        navigationBar.tintColor = UIColor.blueColor()
    
        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
    }
    

提交回复
热议问题