-2

I want to know how to detect changes in a text field. I know we can use Did End On Exit but this works only when once the user finishes typing on the textfield and presses return or clicks elsewhere. I want to know how to detect each entering or deleting of a letter/number in a text field i.e. If the initial text in the text field is badge. As soon as the user presses the delete button to make the text "badg" I want to run a method and once the user presses the delete again to make it "bad" I want to run a method etc.

Thanks:)

user2636368
  • 622
  • 4
  • 10
  • 20

4 Answers4

12

The above can be done in interface builder by right-clicking on the UITextField and dragging the "Editing Changed" send event to your subclass unit.

UITextField Change Event

Siddh
  • 712
  • 4
  • 21
1

Use this delegate method of UITextFieldDelegate...

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

Here string means what you typed newly in textfield. Sometimes this string contains more than one character when you try to paste set of chars.

This delegate method called every time during typing on textfield, If you return NO in this method, your typed char doesn't get updated in text field.

Mani
  • 17,549
  • 13
  • 79
  • 100
0

Use following delegate method UITextField

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

And read official documentation of UITextFieldDelegate Protocol Reference.

iPatel
  • 46,010
  • 16
  • 115
  • 137
0

What about - (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string ?

Valentin Shamardin
  • 3,569
  • 4
  • 34
  • 51