1

In my viewDidLoad, I have the below code to hide the back button. However, when implemented, this disables the back button of further View Controllers in the chain of which I segue to. I'm not sure, but this may be to do with how I structure my app (please see image - note that the Navigation Controller on the far left is connected to a Tab Bar Controller).

// Removes back button
self.tabBarController?.navigationItem.hidesBackButton = true
self.tabBarController?.navigationItem.setHidesBackButton(true, animated: false)
self.tabBarController?.navigationItem.leftBarButtonItem = nil

I've also tried the following code, but this didn't work as well.

self.navigationItem.leftBarButtonItem = nil
self.navigationController?.navigationItem.leftBarButtonItem = nil
navigationItem.setLeftBarButton(nil, animated: false)
self.navigationItem.setLeftBarButton(nil, animated: false)
self.tabBarController?.navigationItem.leftBarButtonItem = nil
self.tabBarController?.navigationItem.setLeftBarButton(nil, animated: false)
self.navigationController?.navigationBar.topItem?.leftBarButtonItem = nil

enter image description here

Annabelle Sykes
  • 121
  • 1
  • 2
  • 10
  • It may be a bit late now, but you should also consider splitting your storyboard into multiple storyboards. Navigating to and from ViewControllers programatically Also consider using R.Swift (this helps in so many ways). https://stackoverflow.com/a/27562874/2472466 – t.ios May 13 '19 at 19:09

2 Answers2

1

If you only want to hide the back button on the current screen you should only clear the leftBarButtonItem. If you hide the backBarButtonItem too that will be applied to the next screen's navigationItem. Does this help?

farkasseb
  • 580
  • 4
  • 15
0

try

self.parent?.navigationItem.setHidesBackButton(true, animated: false)

sometimes the viewController does not recognize it's navigation Controller without self.parent