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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 02-01-2010, 06:19 AM   #1 (permalink)
Vishal
 
Join Date: Feb 2009
Location: Pune, India
Posts: 76
Default Can we control the length of the text in UITextField

Hi,

I want to control the length of the text entered by user in a UITextField. Is there any way to do this?

Vishal N
vishal is offline   Reply With Quote
Old 02-01-2010, 06:35 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 1,015
Default

iirc there is a function in the delegate called each time the text changes.
for each caracter decide if it should be added or not
Tambourin is offline   Reply With Quote
Old 02-01-2010, 07:04 AM   #3 (permalink)
girls? any new species ?
 
sindhutiwari's Avatar
 
Join Date: Nov 2008
Location: INDIA
Posts: 547
Send a message via MSN to sindhutiwari Send a message via Yahoo to sindhutiwari Send a message via Skype™ to sindhutiwari
Default

YES
- (BOOL)textFieldUITextField *)textField shouldChangeCharactersInRangeNSRange)range replacementStringNSString *)string


use this find the length of text filed return NO .. .if it exceeds length



Quote:
Originally Posted by Tambourin View Post
iirc there is a function in the delegate called each time the text changes.
for each caracter decide if it should be added or not
__________________
In order to succeed, your desire for success has to be greater than your fear for failure
sindhutiwari is offline   Reply With Quote
Old 02-01-2010, 07:36 AM   #4 (permalink)
indie dev
 
rocotilos's Avatar
 
Join Date: Oct 2009
Posts: 2,754
Default

Here is what I did... crude way I say, but works... This will clip the user input to 8 character. Assign this to editFinish event outlet.

Code:
-(IBAction)checkName {
	
	int msglen = [UserTextfield.text length];
	NSString *tmpstr;
	NSString *oklength;

	tmpstr = UserTextfield.text;
	oklength = @"";
	
	if (msglen>8) {

		unichar thechar;
		for (int index = 0; index < 8; index += 1)  
		{  
			thechar = [tmpstr characterAtIndex:index];
		    oklength = [NSString stringWithFormat:@"%@%C" , oklength,thechar];
		}
		
		UserTextfield.text = oklength;
	}
}
rocotilos is offline   Reply With Quote
Old 02-01-2010, 08:50 AM   #5 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 1,015
Default


check the NSString class, it has a substring function
Tambourin is offline   Reply With Quote
Reply

Bookmarks

Tags
uitextfield

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
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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