How do I check when a UITextField changes?

后端 未结 19 3145
情话喂你
情话喂你 2020-11-22 15:44

I am trying to check when a text field changes, equivalent too the function used for textView - textViewDidChange so far I have done this:

  fu         


        
19条回答
  •  萌比男神i
    2020-11-22 16:38

    Swift 4.2

    write this in viewDidLoad

    // to detect if TextField changed
    TextField.addTarget(self, action: #selector(textFieldDidChange(_:)),
                                       for: UIControl.Event.editingChanged)
    

    write this outside viewDidLoad

    @objc func textFieldDidChange(_ textField: UITextField) {
        // do something
    }
    

    You could change the event by UIControl.Event.editingDidBegin or what ever you want to detect.

提交回复
热议问题