0

I am trying to get a character count while typing into a UITextField. I use UIControlEventEditingChanged notification to then get the current count:

[textField addTarget:self action:@selector(handleTextDidChange:) forControlEvents:UIControlEventEditingChanged];

The code is working fine and fired whenever I type any new characters into the field. It is also fired whenever I delete any characters EXCEPT for when it is the only remaining character in the text field.

Any ideas why?

Sam
  • 7,252
  • 16
  • 46
  • 65
JimmyJammed
  • 9,598
  • 19
  • 79
  • 146

1 Answers1

0

I tested your code and it was working fine for me in iOS 7.1. What you could try is:

Make your ViewController implement

<UITextFieldDelegate> 

and set

textfield.delegate = self;

And implement the following function, which also always get called, whenever a character should be changed (even the last one). Make sure to always return YES if the character should be changed. With the range and textfield.text you can always access the current character to be changed:

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

    return YES;

}
Muxor
  • 161
  • 7