Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-26-2010, 12:08 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: india
Posts: 65
sharhelia is on a distinguished road
Question limiting characters in uitextview

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
sharhelia is offline   Reply With Quote
Old 04-26-2010, 02:14 PM   #2 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 624
DenVog is on a distinguished road
Default

Quote:
Originally Posted by sharhelia View Post
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
There are some existing threads related to this that might help you.
DenVog is offline   Reply With Quote
Old 05-03-2010, 07:24 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: india
Posts: 65
sharhelia is on a distinguished road
Default

Quote:
Originally Posted by sharhelia View Post
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)textViewUITextView *)textView shouldChangeTextInRangeNSRange)range replacementTextNSString *)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;

}
sharhelia is offline   Reply With Quote
Reply

Bookmarks

Tags
characters, limit, twitter, uitextview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 315
21 members and 294 guests
Abidullah, baja_yu, cgokey, Domele, Duncan C, Fstuff, gbenna, givensur, guusleijsten, HowEver, iphonedevshani, jbro, JoeRCruso, mdpauley, n00b, newDev, seokwon lee, SLIC, stanny, Steven.C, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,876
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:36 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0