UITextField Value Changed Event?

Christian Stewart picture Christian Stewart · Oct 23, 2010 · Viewed 38.9k times · Source

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

Answer

kovpas picture kovpas · Oct 23, 2010

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) {...}