I'm trying to disable a navigation bar back button item (turning to gray and does not respond to touches).
I tried the following :
[self.navigationItem.backBarButtonItem setEnabled:NO];
Which does not work. Disabling the right button item works as a charm.
Surprisingly enough I could not find a similar question on SO. The closest one was about hiding the button (which works btw) but this is not so elegant (or adding a label to cover the button and prevent touches which keeps the same color of the back button --> also not so elegant:/).
I should mention that the view controller is a table view controller which is pushed by another navigation controller. (i.e. the back button is added automatically and not via IB or programmaticaly)
Any ideas ?
Touch “Settings” -> “Display” -> “Navigation bar” -> “Full screen gestures”. The navigation bar will be hidden and you will be shown “Gesture demos” to explain how to operate the “Go back”, “Go to Home screen” and “Open Recents” functions.
Yes, the back button can be disabled. 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.
The . navigationBarBackButtonHidden(true) will hide the back button.
The navigation item used to represent the view controller in a parent's navigation bar.
You can hide using
[self.navigationItem setHidesBackButton:YES animated:YES];
You do need to create a custom back button in order to disable it. Here's a simple example (No need to hide the backButtonItem):
Note that you'll probably want to disable the back swipe gesture (see here: How to disable back swipe gesture in UINavigationController on iOS 7 )
class MyClass: UIViewController {
private var backButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
backButton = UIBarButtonItem(title: "Back", style: .Plain, target: self, action: "goBack")
navigationItem.leftBarButtonItem = backButton
}
func goBack() {
navigationController?.popViewControllerAnimated(true)
}
func toggleBackButton() {
backButton.enabled = (backButton.enabled == false) ? true : false
}
}
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