开发者

UITextField shouldChangeCharactersInRange stops getting called if I press backspace for a long time

开发者 https://www.devze.com 2023-03-13 14:48 出处:网络
If I type开发者_StackOverflow a very long text in my UITextField, for example: 123456789012345678901234567890.

If I type开发者_StackOverflow a very long text in my UITextField, for example: 123456789012345678901234567890.

Now if I press the backspace and leave it pressed, then the shouldChangeCharactersInRange is called for some characters in the beginning.

But, then when the UITextField start getting cleared with a fast speed, the shouldChangeCharactersInRange stops getting called. Can anyone suggest me a solution.


You can add observer for the UITextFieldTextDidChangeNotification which will be posted whenever the text changes in text field.

[[NSNotificationCenter defaultCenter] 
     addObserver:self 
     selector:@selector(yourMethod:)
     name:UITextFieldTextDidChangeNotification 
     object:yourTextField];

In this case, yourMethod: method will always work.

0

精彩评论

暂无评论...
验证码 换一张
取 消