I am trying to check when a text field changes, equivalent too the function used for textView - textViewDidChange
so far I have done this:
func textFieldDidBeginEditing(textField: UITextField) {
if self.status.text == "" && self.username.text == "" {
self.topRightButton.enabled = false
} else {
self.topRightButton.enabled = true
}
}
Which kind of works, but the topRightButton
is enabled as soon as the text field is pressed on, I want it to be enabled only when text is actually typed in?
The way I've handled it so far : in
UITextViewDelegate
Swift4 version
Swift 4
Conform to UITextFieldDelegate.
Swift 3.0
and handle method:
Swift 4.0
and handle method:
Swift 3
This is how you can add a
textField text change listener
using Swift 3:Declare your class as
UITextFieldDelegate
Then just traditionally add a textFieldShouldEndEditing function:
You can use this delegate method from UITextFieldDelegate. It fires with every character change.
However THIS ONLY FIRES BEFORE a change is made (indeed, a change is only made if you do return true from here).