2

So, I have the delegate method

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

running to check if a textfield has a minimum of 1 character in it.

Well, if the number of characters exceeds 20 or so, when the user holds down the delete button for a second or two it deletes the entire word, jumping over the delegate check and deleting all the way down to 0 characters.

Does anyone know how to turn this 'fast delete' off?

Can it even be done, or is there a decent work-around I am not seeing?

I should also point out this is a single word that will be put in this textfield by the user.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Justin
  • 464
  • 5
  • 14
  • What will you suppose to do if user will mark several letters as block and delete it as whole or change it with one letter? That's the reason why this method operates with ranges but not separate characters. – Valeriy Van Sep 23 '11 at 17:32

2 Answers2

1

No way. What will you do if user will mark several letters as block and delete it as whole or change it with one letter? That's the reason why this method operates with ranges but not separate characters.

Valeriy Van
  • 1,851
  • 16
  • 19
  • I actually have code in there that handles deleting or adding content in blocks thanks to [here](http://stackoverflow.com/questions/433337/iphone-sdk-set-max-character-length-textfield).I went ahead and changed up my code to allow users to delete everything. – Justin Sep 23 '11 at 20:54
0

Code in

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

or

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ 
    if (![text length]&&range.length&&range.length!=1){
        return NO;
    }
JJJ
  • 32,902
  • 20
  • 89
  • 102
cocoa
  • 11
  • 6