How do I get the back bar button item to show up in my navigation item in iOS?

I am not able to show a back bar button item in my navigation item in my root view controller of my navigation controller.


I have tried setting different properties.


Other questions like this do not give me an answer that works.


Her is my code in my root view controller:


    override func viewDidLoad() {
        super.viewDidLoad()


        print("viewDidLoad")
       
        navigationItem.leftItemsSupplementBackButton = true
        navigationItem.backBarButtonItem = UIBarButtonItem(title: "Button", style: .plain, target: nil, action: nil)
        navigationItem.setHidesBackButton(false, animated: true)
        navigationItem.leftItemsSupplementBackButton = true


    }

Accepted Reply

The way I did this:

- I added (drag & drop in IB) a UIBarButtonItem in the navigation bar of the rootViewController

- Created an IBOutlet to reference it if I need to change title, or color

- Connected this button to the exit button of the RootViewController to unwind to where I need

Replies

The way I did this:

- I added (drag & drop in IB) a UIBarButtonItem in the navigation bar of the rootViewController

- Created an IBOutlet to reference it if I need to change title, or color

- Connected this button to the exit button of the RootViewController to unwind to where I need

I thought the back bar button item was supposed to show up automatically.

I've had this problem for a long time. I wonder if I'm supposed to embed a view controller in a navigaton controller every time, so that the view controller shows a navigation item.