how to disable a navigation bar button item in iOS

前端 未结 16 1263
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 09:54

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

16条回答
  •  有刺的猬
    2021-01-01 10:16

    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!
    }
    

提交回复
热议问题