Search code examples
iosswiftuinavigationcontrolleruinavigationbaruinavigationitem

Unable to change backBarButtonItem in Swift


I want to make my backBarButtonItem to be only < , without back. I have searched stackOverflow and found some solutions, but it stays < back.
I tried this in my pushed VC:

navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

and also this, in my AppDelegate:

navigationController.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

But none of two helped me. Anyone knows why?
This is how I push my ViewControllers:

let VC = XYZViewController()
self.navigationController?.pushViewController(VC, animated: true)

Solution

  • navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    

    Write this piece of code in the controller from which you are pushing to the next controller