Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField Value Changed Event?

How can I make it so that when the contents of a text field changes, a function is called?

like image 280
Christian Stewart Avatar asked Oct 23 '10 21:10

Christian Stewart


People also ask

How can I get my UITextField value?

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.

What is a UITextField?

An object that displays an editable text area in your interface.


2 Answers

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) {...}
like image 160
kovpas Avatar answered Oct 22 '22 03:10

kovpas


Actually, there is no value changed event for UITextField, use UIControlEventEditingChanged

like image 26
Dmitry Shevchenko Avatar answered Oct 22 '22 02:10

Dmitry Shevchenko