当我从键盘输入每个字符时,我试图添加空格,但问题是我无法删除、复制或编辑文本。
- (BOOL) textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string
{
NSUInteger length = [textField.text length] + [string length] - range.length;
if ([textField tag] == textTag && newLength <= 10) {
textField.text = [textField.text stringByAppendingString:@" "];
length ++;
NSLog(@"%d", length);
} else {
NSLog(@"%d", length);
return NO;
}
return YES;
}