解决方法
-(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