迅速
斯威夫特4.2
textfield.addTarget(self, action: #selector(ViewController.textFieldDidChange(_:)), for: .editingChanged)
和
@objc func textFieldDidChange(_ textField: UITextField) {
}
SWIFT 3和Swift 4.1
textField.addTarget(self, action: #selector(ViewController.textFieldDidChange(_:)), for: .editingChanged)
和
func textFieldDidChange(_ textField: UITextField) {
}
SWIFT 2.2
textField.addTarget(self, action: #selector(ViewController.textFieldDidChange(_:)), forControlEvents: UIControlEvents.EditingChanged)
和
func textFieldDidChange(textField: UITextField) {
//your code
}
目标C
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
和textFieldDidChange方法是
-(void)textFieldDidChange :(UITextField *) textField{
//your code
}