How to hide 'Back' button on navigation bar on iPhone?

Viewed 187876

I added a navigation control to switch between views in my app. But some of the views shouldn't have 'Back' (the previous title) button. Any ideas about how to hide the back button?

15 Answers

Objective-C:
self.navigationItem.hidesBackButton = YES;

Swift:
navigationItem.hidesBackButton = true

Don't forget that we have the slide to back gesture now. You probably want to remove this as well. Don't forget to enable it back again if necessary.

if ([self.navigationItem respondsToSelector:@selector(hidesBackButton)]) {
    self.navigationItem.hidesBackButton = YES;
}

if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

try this one - self.navigationController?.navigationItem.hidesBackButton = true

In c# or Xamarin.ios, this.NavigationItem.HidesBackButton = true;

navigationItem.leftBarButtonItem = nil
navigationItem.hidesBackButton = true

if you use this code block inside didLoad or loadView worked but not worked perfectly.İf you look carefully you can see back button is hiding when your view load.Look's weird.

What is the perfect solution?

Add BarButtonItem component from componentView (Command + Shift + L) to your target viewControllers navigation bar.

Select BarButtonItem set Title = " " from right panel

enter image description here

self.navigationItem.setHidesBackButton(true, animated: true)
Related