Left Bar Button Item - show name of previous View Controller

12,525

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]
}
Share:
12,525
Mikael Weiss
Author by

Mikael Weiss

I am an iOS app developer and contractor. I have been in the field for about a year. My specialty is SwiftUI, and I’ve spent most of my time in the Clean Swift architecture and a little MVVM as well.

Updated on June 04, 2022

Comments

  • Mikael Weiss
    Mikael Weiss almost 2 years

    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?