我想限制用户在 UITextField 中输入空间。为此我使用此代码
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ( string == @" " ){
UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"You have entered wrong input" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[error show];
return NO;
}
else {
return YES;
}
}
但它不起作用....有什么问题?