Limit number of charchters in uitextview !

Posted by hib on Stack Overflow See other posts from Stack Overflow or by hib
Published on 2010-03-22T12:45:33Z Indexed on 2010/03/22 12:51 UTC
Read the original article Hit count: 577

Filed under:
|

Hello All ,

I am giving a text view to tweet some string .

I am applying the following method to restrict the number of characters to 140 in length.

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{


    if([text isEqualToString:@"\b"]){
        DLog(@"Ohoooo");
        return YES;
    }else if([[textView text] length] > 140){

        return NO;
    }

    return YES;
}

The code is working nicely except the first condition that backspace is not working. suppose that I have reached the limit of 140 characters so that the method will give me false and the user can not insert more characters but after that when I try to delete some characters the text view behave as it is disabled .

So the question how do delete characters from textview.text or re-enable the text view .

© Stack Overflow or respective owner

Related posts about uitextviewdelegate

Related posts about iphone