I got a UITextField
zipTextField and use UIPicker
to change the text. And I want to know when the zipTextField is changed.
I put this program in my ViewController
@IBAction func textFieldEditingDidChange(sender: AnyObject){
print("textField:\(zipTextField.text)")
}
And Connected to the View with Editing Changed Event
But the function didn't call when zipTextField has changed
Otherwise when I connect textFieldEditingDidChange
to Editing Did End or Editing Did Begin textFieldEditingDidChange will be called
If you have implemented the delegate method
textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String)
and returned false
, the event is not fired.
Usually this is because you're trying to manually set textfield's value (textField.text = newValue
) preventing the user input.
If so, you have to add:
textField.sendActions(for: .editingChanged)
before returning false
and after textField.text = newValue
in the delegate method. This will send the UIControl
Event
back to your observer.
If delegate function
textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String)
returns false
,
then function that set on .editingChanged
will not call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With