I have a way of hiding the back button used by the navigation controller. It's set by the previous controller, not the one managing the current view, and that makes it tricky to get to. I needed to do this in editing mode so that I could prevent the user from navigating away from the screen.
if(self.editing) {
// Get rid of the back button
UIView *emptyView = [[UIView alloc] init];;
UIBarButtonItem *emptyButton = [[[UIBarButtonItem alloc] initWithCustomView:emptyView] autorelease];
[self.navigationItem setLeftBarButtonItem:emptyButton animated:YES];
} else {
// Restore the back button
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
}
Is there a better way to do this?
Go to attributes inspector and uncheck show Navigation Bar to hide back button.
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.
Swift5:
self.navigationItem.setHidesBackButton(true, animated: false)
use this to hide back button
[self.navigationItem setHidesBackButton:YES]
use this to show back button
[self.navigationItem setHidesBackButton:NO]
Here's the method I use in my view controller to show and hide the back button when editing is enabled and disabled:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
if (editing) {
// Disable the back button
[self.navigationItem setHidesBackButton:YES animated:YES];
}
else {
// Enable the back button
[self.navigationItem setHidesBackButton:NO animated:YES];
}
[super setEditing:editing animated:animated];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With