I have created a navigation controller. In the second view (which is pushed), I have some webservice call and placing a overlay view and setting
self.view.use
Swift 5 It's working for Navigation controller
//Disable
self.navigationController?.navigationBar.isUserInteractionEnabled = false
//Enable
self.navigationController?.navigationBar.isUserInteractionEnabled = true
Updated for Swift 3:
If you want to disable a navigation bar button item OR you want to disable hole UINavigationBar i.e. all item present on navigation bar, use below lines of code;
// if you want disable
self.navigationController?.navigationBar.isUserInteractionEnabled = false
// if you want enable again
self.navigationController?.navigationBar.isUserInteractionEnabled = true
Enjoy...!
One line solution
self.navigationItem.leftBarButtonItem.enabled = NO;
self.navigationItem.rightBarButtonItem.enabled = NO;
The simplest way to truly disable a UIBarButtonItem would be as followed:
barButtonVar.isEnabled = false
Navigation bar button items must be toggled by referring to them via the navigationItem property.
For example:
func setupNav() {
let saveButton = UIBarButtonItem.init(barButtonSystemItem: .save, target: self, action: #selector(onSavePressed))
navigationItem.rightBarButtonItem = saveButton
saveButton.isEnabled = false
}
func validateSave() {
saveButton.isEnabled = isConditionMet // WON'T work
navigationItem.rightBarButtonItem.isEnabled = isConditionMet // WORKS!
}
For version iOS 10.3, swift 3:
self.navigationItem.rightBarButtonItem?.isEnabled = false.