Quote:
Originally Posted by sharhelia
Hi
i am making a twitter app to post the tweets. As we can post maximum 140 characters in length. So i want to restrict the user from entering characters more than 140 for that i am using a label to show the characters remaining , the problem is that i am using \b to detect backspace but its not working, when the count remains 0 in the label i make the textview uneditable but i want that user can enter backspace to edit the text.
does anyone know how to allow only 140 characters in uitext view. Please help me guys.
thanks
|
i have got the solution for this problem. i did this to handle this and it is working fine
- (BOOL)textView

UITextView *)textView shouldChangeTextInRange

NSRange)range replacementText

NSString *)text
{
BOOL flag = NO;
NSLog(@"the text is %@",text);
NSLog(@"the length is %i",[text length]);
if([text length] == 0)
{
if([textView.text length] != 0)
{
flag = YES;
NSString *Temp = charbutton.title;
int j = [Temp intValue];
j = j +1 ;
charbutton.title = [[NSString alloc] initWithFormat:@"%i",j];
return YES;
}
else {
return NO;
}
}
else if([[textView text] length] > 139)
{
return NO;
}
if(flag == NO)
{
charbutton.title = [[NSString alloc] initWithFormat:@"%i",139-[textView.text length]];
}
return YES;
}