How can I make it so that when the contents of a text field changes, a function is called?
Just use the text attribute of the UITextField to get the value (which is a String). Then, use the toInt() method (which returns an optional) to convert that to an Integer, so that you can perform mathematical operations.
An object that displays an editable text area in your interface.
Objective-C
[myTextField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
Swift 4
myTextField.addTarget(self, action: #selector(textFieldDidChange(sender:)), for: .editingChanged)
@objc func textFieldDidChange(sender: UITextField) {...}
Actually, there is no value changed event for UITextField
, use UIControlEventEditingChanged
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