Reputation: 44312
For a UITextField, what is the best way to detect if the user is typing and the textfield has a value?
I've tried the following unsuccessfully:
Upvotes: 0
Views: 2094
Reputation: 5765
Try using the shouldChangeCharactersInRange
event.
func textField(textField: UITextField,
shouldChangeCharactersInRange range: NSRange,
replacementString string: String)
-> Bool {
// Put your code here
}
This is called whenever a user adds or removes a new character to your UITextField
.
If you want to accept the change, return true
. Otherwise return false
.
Just make sure your UITextField conforms to the UITextFieldDelegate
Protocol
Upvotes: 2