20

How can I disable the back button from the detail view controller?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Zahi S.
  • 239
  • 1
  • 2
  • 5
  • You can cover the Back button and intercept touches: [http://stackoverflow.com/a/14954425/236415](http://stackoverflow.com/a/14954425/236415) In a similar fashion, you could cover and hide the Back button using an image that matches a blank portion of the navigation bar. – Jeff Mar 05 '13 at 10:21
  • 1
    This is not off topic, it's the first google result for how to disable the back button on iOS. – Adrian Macneil Sep 18 '15 at 20:21

2 Answers2

45

Depending on your configuration:

self.navigationItem.hidesBackButton = YES;

OR:

self.navigationController.navigationItem.hidesBackButton = YES;

Or, if you just want to disable the button without hiding it, you can use this.

self.navigationController.navigationItem.backBarButtonItem.enabled = NO;
TheTiger
  • 13,264
  • 3
  • 57
  • 82
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
  • 19
    I realize this is very old, but I want to disable the button without hiding it. `self.navigationItem.hidesBackButton=NO` does indeed hide the back button, but `self.navigationController.navigationItem.backBarButtonItem.enabled=NO` does not disable the back button. (Neither does `self.navigationItem.backBarButtonItem.enabled=NO`) – ToddB Sep 24 '14 at 00:20
  • did the `self.navigationController.navigationItem.backBarButtonItem.enabled = NO;` ever work? – Daniel Fernandes Jun 14 '16 at 11:30
15

You can use the UINavigationItem hidesBackButton to hide it:

self.navigationItem.hidesBackButton = YES;
TheTiger
  • 13,264
  • 3
  • 57
  • 82
gsempe
  • 5,371
  • 2
  • 25
  • 29
  • 4
    I think `hidesBackButton` is a property of `UINavigationItem` rather than `UINavigationController` – elitalon Mar 19 '13 at 16:22