7

If you have a Navigation Controller with no Bar Button Items, a navigation back button will be shown with the name of the last View Controller.

I want to keep that name, as in I don't want to have to hardcode it. I do know how to add it in but I don't want to have to do that because that leaves more room for bugs.

Is there a way that I can have a left Bar Button Item and for the default one to not go away?

pkamb
  • 33,281
  • 23
  • 160
  • 191
Mikael Weiss
  • 839
  • 2
  • 14
  • 25

1 Answers1

18

Add this in viewController where you want to have default back button and custom bar button item. You can customise the bar button item.

override func viewDidLoad() {
    super.viewDidLoad()
    let newBtn = UIBarButtonItem(title: "new", style: .plain, target: self, action: #selector(anotherMethod))
    self.navigationItem.leftItemsSupplementBackButton = true
    self.navigationItem.leftBarButtonItem = newBtn//self.navigationItem.leftBarButtonItems = [newBtn,anotherBtn]
}
RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70