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.
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.