Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the "back" button in UINavigationController?

People also ask

How do I make my back button invisible?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How can hide back button in IOS?

To hide the back button on navigation bar we'll have to either set the navigation button as nil and then hide it or hide it directly. Let's create a project, add 2 view controller and Embed them in navigation controller.

How do I hide the back button in SwiftUI?

Use navigationBarBackButtonHidden(_:) to hide the back button for this view. This modifier only takes effect when this view is inside of and visible within a NavigationView . Note: When applying this modifier, your navigation view will also lose the ability to swipe back.


I just found out the answer, in a controller use this:

[self.navigationItem setHidesBackButton:YES animated:YES];

And to restore it:

[self.navigationItem setHidesBackButton:NO animated:YES];

--

[UPDATE]

Swift 3.0:

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

Add this Code

[self.navigationItem setHidesBackButton:YES];

In addition to removing the back button (using the methods already recommended), don't forget the user can still 'pop' to the previous screen with a left-to-right swipe gesture in iOS 7 and later.

To disable that (when appropriate), implement the following (in viewDidLoad for example):

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
     self.navigationController.interactivePopGestureRecognizer.enabled = NO;

Just to clarify existing answers: the hidesBackButton property is the right answer, but it isn't clear in many answers what self refers to. Basically you should set self.navigationItem.hidesBackButton = YES in the view controller that is about to get pushed (or just got pushed) onto the UINavigationController.

In other words, say I have a UINavigationController named myNavController. I want to put a new view on it, and when I do I don't want the back button to show anymore. I could do something like:

UIViewController *newVC = [[UIViewController alloc] init];
//presumably would do some stuff here to set up the new view controller
newVC.navigationItem.hidesBackButton = YES;
[myNavController pushViewController:newVC animated:YES];

When the code finishes, the view controlled by newVC should now be showing, and no back button should be visible.