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?
textField(_:shouldChangeCharactersIn:replacementString:) worked for me in Xcode 8, Swift 3 if you want to check every single keypress.
Swift 4
If you want to make a change once the user has typed in completely (It will be called once user dismiss keyboard or press enter).
Maybe use RxSwift ?
need
add imports obviously
So u have a
textfield : UITextField
U have other 3 methods..
You can make this connection in interface builder.
In your storyboard, click the assistant editor at the top of the screen (two circles in the middle).
Ctrl + Click on the textfield in interface builder.
Drag from EditingChanged to inside your view controller class in the assistant view.
Name your function ("textDidChange" for example) and click connect.
You should follow this steps:
Sample code: