4thSpace
4thSpace

Reputation: 44312

Detecting if the user is typing?

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

Answers (1)

MLyck
MLyck

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

Related Questions