 |
 |
|
 |
02-01-2010, 06:19 AM
|
#1 (permalink)
|
|
Vishal
Join Date: Feb 2009
Location: Pune, India
Posts: 76
|
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
|
|
|
02-01-2010, 06:35 AM
|
#2 (permalink)
|
|
Registered Member
Join Date: Sep 2009
Posts: 1,015
|
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
|
|
|
02-01-2010, 07:04 AM
|
#3 (permalink)
|
|
girls? any new species ?
Join Date: Nov 2008
Location: INDIA
Posts: 547
|
YES
- (BOOL)textField  UITextField *)textField shouldChangeCharactersInRange  NSRange)range replacementString  NSString *)string
use this find the length of text filed return NO .. .if it exceeds length
Quote:
Originally Posted by Tambourin
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
|
|
|
02-01-2010, 07:36 AM
|
#4 (permalink)
|
|
indie dev
Join Date: Oct 2009
Posts: 2,754
|
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;
}
}
|
|
|
02-01-2010, 08:50 AM
|
#5 (permalink)
|
|
Registered Member
Join Date: Sep 2009
Posts: 1,015
|

check the NSString class, it has a substring function
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 254 |
| 26 members and 228 guests |
| ADY, AragornSG, bookesp, chillyh, ckgni, dacapo, Dani77, Davey555, Desert Diva, Dominus, glenn_sayers, HemiMG, JasonR, LEARN2MAKE, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, ryantcb, themathminister, theone8one |
| Most users ever online was 1,187, 10-11-2011 at 08:09 AM. |
» Stats |
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
|
| Welcome to our newest member, bookesp |
|