Enable a button in Swift only if all text fields have been filled out

前端 未结 10 758
误落风尘
误落风尘 2020-12-01 01:20

I am having trouble figuring out how to change my code to make it so the Done button in the navigation bar is enabled when my three text fields are filled out.

I cur

10条回答
  •  庸人自扰
    2020-12-01 01:34

    You can create an array of text fields [UITextField] or an outlet collection. Let's call the array textFields or something like that.

    doneBarButton.isEnabled = !textFields.flatMap { $0.text?.isEmpty }.contains(true)
    

    And call the code above in a method that monitors text field's text changes.

提交回复
热议问题