Changing navigation title programmatically

后端 未结 14 2191
长情又很酷
长情又很酷 2020-11-28 19:34

I have a navigation bar with a title. When I double click the text to rename it, it actually says it\'s a navigation item, so it might be that.

I\'m trying to change

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 19:50

    I prefer using self.navigationItem.title = "Your Title Here" over self.title = "Your Title Here" to provide title in the navigation bar since tab bar also uses self.title to alter its title. You should try the following code once.

    Note: calling the super view lifecycle is necessary before you do any stuffs.

    class ViewController: UIViewController {
        override func viewDidLoad() {
            super.viewDidLoad()
            setupNavBar()
        }
    }
    
    private func setupNavBar() {
        self.navigationItem.title = "Your Title Here"
    }
    

提交回复
热议问题