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

前端 未结 3 2265
长情又很酷
长情又很酷 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:48

    I was unnecessarily creating two navigation bars. The navigation controller comes with a navigation bar, and I changed my ViewController to:

    class ViewController: UIViewController, UINavigationBarDelegate {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            self.navigationItem.title = "My Title"
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Left Button", style:   UIBarButtonItemStyle.Plain, target: self, action: nil)
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Right Button", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
        }
    
        func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
            return UIBarPosition.TopAttached
        }
    
    }
    

提交回复
热议问题