self.navigationController?.navigationBar.backItem?.title = "Back"
I want to set back button text on navigation bar But I can't. This Code Not Working.
self.navigationController?.navigationBar.backItem?.title = "Back"
I want to set back button text on navigation bar But I can't. This Code Not Working.
Try this one
let backItem = UIBarButtonItem()
backItem.title = "Text"
navigationItem.backBarButtonItem = backItem //
As per the comment of @Boobesh, the solution that worked as per the question:
let vc = ViewController()
self.navigationItem.backBarButtonItem = UIBarButtonItem(title : "Back", style:.plain, target:nil, action:nil)
self.navigationController?.pushViewController(vc, animated: true)
Try adding this code in the view controller one level up the stack.
If you are moving from controller A to B, write this code on A to see the effect on B.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let backItem = UIBarButtonItem()
backItem.title = "Back"
navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}
Use this code.
navigationItem.backBarButtonItem = UIBarButtonItem(title: "Text", style: .plain, target: nil, action: nil)
Add this code to the controller (viewDidLoad method for instance) to which you return, not the one from which you are returning. So, if the stack of view controllers looks like:
ViewController1 -> ViewController2
and you want to change the back button title on the ViewController2
, you need to change the backbuttonItem
of the ViewController1
.