1

My question is simple, How to hide back button in navigation bar? I see similar question here in stack overflow but

self.navigationItem.hidesBackButton = YES;

not working for me. I am using below code because RootViewController is my Singleton class.

Thanks

i still use both in viewDidLoad but both are not working

[RootViewController sharedFirstViewController].navigationItem.hidesBackButton = YES;

[RootViewController sharedFirstViewController].navigationItem.backBarButtonItem=nil;
Community
  • 1
  • 1
QueueOverFlow
  • 1,336
  • 5
  • 27
  • 48

2 Answers2

2

Try self.navigationItem.backBarButtonItem.hidden = YES; or self.navigationItem.backBarButtonItem = nil;

Place one of these either in viewWillAppear:, viewWillLoad or viewDidAppear: of the class you want to get rid of the back button in.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
1

I suggest doing this before the view appears on the screen. You probably dont want to see the bar and then have it disappear.

So you should call:

- (void) viewDidLoad {
   //Check to see if the Nav har is hidden, and then hide it
   if (!self.navigationItem.backBarButtonItem.hidden) {
      self.navigationItem.backBarButtonItem.hidden = YES;
   }
   else { 
      NSLog(@"back button already hidden");
   }
}

Note that you can also do this with the whole nav bar completely, if you're trying to free up screen space.

bkbeachlabs
  • 2,121
  • 1
  • 22
  • 33