How to prevent keyboard changing from Numbers to Alphabet when the space key is touched?

无人久伴 提交于 2019-12-05 11:09:09

I do not think it is possible to modify the keyboard behavior.

However, you could implement the textField:shouldChangeCharactersInRange:replacementString: from the UITextFieldDelegate protocol to intercept the space (and apostrophe) like this and it seems to work:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if ([string isEqualToString:@" "] || [string isEqualToString:@"'"]) {
        NSMutableString *updatedString = [NSMutableString stringWithString:textField.text];
        [updatedString insertString:string atIndex:range.location];
        textField.text = updatedString;
        return NO;
    } else {
        return YES;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!