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

iphone, iphone-sdk-3.0, uitextfield

Solution

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;
    }
}

Problem

I have `UITextFields` on a table to enter values. Some of these fields accept only numbers. I am using `UIKeyboardTypeNumbersAndPunctuation` for the keyboardType, and `shouldChangeCharactersInRange` to filter the characters. Also, all the corrections are disabled: ``` textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; textField.autocorrectionType = UITextAutocorrectionTypeNo; textField.autocapitalizationType = UITextAutocapitalizationTypeNone; ``` On the numeric only fields, when the space key is touched, the keyboard changes to Alphabet. I know that this is the default behavior. I want to ignore the space key, and don't want the keyboard type change. Is there some way to change this default behavior? PS: the other numeric keyboard types are not an option. I need the Punctuation! Thanks

Original source