Detecting a change to text in UITextfield

前端 未结 7 2013
轮回少年
轮回少年 2021-02-07 02:15

I would like to be able to detect if some text is changed in a UITextField so that I can then enable a UIButton to save the changes.

相关标签:
7条回答
  • 2021-02-07 02:55

    This can be accomplished in Interface Builder on the Editing Changed event of UITextField. Drag from it to your code and create an IBAction.

    For example:

    @IBAction func textFieldChanged(_ sender: UITextField) {
      print(sender.text)
    }
    

    This event is the same as described in other answers here in that the .text property contains the updated text input when it gets triggered. This can help clean up code clutter by not having to programmatically add the event to every UITextField in the view.

    0 讨论(0)
提交回复
热议问题