i want to restrict user from entering space in a UITextField. for this i m using this code
- (BOOL)textField:(UITextField *)textField shouldChangeCharacters
Try this (set this in your - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string):
NSArray *escapeChars = [NSArray arrayWithObjects:@" ", nil];
NSArray *replaceChars = [NSArray arrayWithObjects:@"",nil];
int len = [escapeChars count];
NSMutableString *temp = [[textField text] mutableCopy];
for(int i = 0; i < len; i++) {
[temp replaceOccurrencesOfString: [escapeChars objectAtIndex:i] withString:[replaceChars objectAtIndex:i] options:NSLiteralSearch range:NSMakeRange(0, [temp length])];
}
[textField setText:temp];
return TRUE;