Problem with iPhone sdk 3.0

I set maxlength in my textField, when I entered the maximum characters in the text box, backspace does not work. Because of this, I cannot change the contents of textFields. This happens when I test my application on iPhone sdk 3.0, but it works correctly on iPhone sdk 2.2.

Here is my code

- (BOOL)textField:(UITextField *)txtField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (txtField.text.length >= 15 && range.length == 0)
    {
        return NO; 
    }
    else
    {
        return YES;
    }
}

Why does this happen in iPhone sdk 3.0?

0
source share
1 answer

The top of my head range.length == 0will return true for the backspace character, so you explicitly return NOwhen the user removes the backspace in the full text field. I would suggest changing the first condition as follows:

if ( txtField.text.length + range.length > 15 )
    return ( NO );

... , ( ), OS 3.0, .

0

All Articles