How to Change back button title on navigation controller in swift3?

后端 未结 8 578
天命终不由人
天命终不由人 2020-12-06 18:54

I want to change the title of backbutton to any name in swift 3.I tried many ways but none of them worked for me.

self.navigationItem.backBarButtonItem?.titl         


        
8条回答
  •  日久生厌
    2020-12-06 19:21

    I didn't find the answer that I was looking for so I share with you my solution.

    Sometimes you have to change the text of the back button in the parent ViewController and not in the ViewController where seems to be defined the back button, remember that a navigation controller stack ViewControllers one after another.

    In my case I did this on the function prepare(for segue: ) of the "ParentViewController":

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    
        if segue.identifier == "showChildViewController" {
            if let childViewController = segue.destination as? ChildViewController {
                let backItem = UIBarButtonItem()
                backItem.title = "Back"
                navigationItem.backBarButtonItem = backItem
            }
        }
    

提交回复
热议问题