Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 UINavigationController disable Back Button

in my Navigation Controller I need to temporarily disable the back button. I know that it can be hidden using the following or something similar:

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

But that is not what I need, instead I want the back button to be greyed out and non-responsive to user touch events. Is their a way to achieve this without replacing the default back button?

Thanks in advance!

like image 239
David Silverfarmer Avatar asked Nov 06 '14 09:11

David Silverfarmer


People also ask

How to disable back button in iOS?

Please navigate to Advanced Website Kiosk Settings–>Navigation–>Disable back button. Kindly enable this restriction to disallow the usage of the back button on the iOS device.

How do I show the back button in Swift?

Back-button text is taken from parent view-controller's navigation item title. So whatever you set on previous view-controller's navigation item title, will be shown on current view controller's back button text. You can just put "" as navigation item title in parent view-controller's viewWillAppear method.


2 Answers

To disable the back button, these commands would make it do what you want it to do:

Enable:

self.navigationController.navigationBar.userInteractionEnabled = YES;
self.navigationController.navigationBar.tintColor = [UIColor blueColor];

Disabled:

self.navigationController.navigationBar.userInteractionEnabled = NO;
self.navigationController.navigationBar.tintColor = [UIColor lightGrayColor];

Update:

As of iOS 7, there's also a swipe that you'll want to disable on the UINavigationBar.

// You wrap it an 'if' statement so it doesn't crash
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
// disable the interactivePopGestureRecognizer
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
like image 196
Adrian Avatar answered Sep 21 '22 13:09

Adrian


This hides the back button, so it becomes unreachable for the user. And it disables the swipe gesture.

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

Swift:

navigationItem.setHidesBackButton(true, animated: true)

See more info in Apple's documentation.

like image 38
Evgeny Karpov Avatar answered Sep 21 '22 13:09

Evgeny Karpov