我有一个问题,当在iOS7上对齐一个UITextField时,当用户键入“空格”时,它不会马上出现.如果我键入另外一个字符空格出现.
在iOS 6中并没有发生
任何人都知道如何解决这个问题?
解决方法
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (range.location == textField.text.length && [string isEqualToString:@" "]) { // ignore replacement string and add your own textField.text = [textField.text stringByAppendingString:@"\u00a0"]; return NO; } // for all other cases,proceed with replacement return YES; }
从文本中删除代码
self.txtFirstName.text = [self.txtFirstName.text stringByReplacingOccurrencesOfString:@"\u00a0" withString:@" "];
从这个stackoverflow答案 – UITextField spacebar does not advance cursor in iOS 7