Change UIKeyboardType based on text input

I am trying to change the UIKeyboardType to an alphabet keyboard when the user enters a space, reflecting the effect of entering an apostrophe. However, my code will not change the appearance of the keyboard until the user rejects the keyboard and then returns it again.

Edit: To clarify, the keyboard type starts with UIKeyboardTypeNumbersAndPunctuation, and I want to switch to ASCIICapable, because the typical user input is in the form of "flour # cups". I realized that the ASCIICapable keyboard has built-in functionality, so the presentation of an ASCII-compatible keyboard, but showing numbers / punctuation, will work first.

Here is my code:

- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([string isEqualToString:@" "]) { textField.keyboardType = UIKeyboardTypeASCIICapable; } return YES; } 
+8
ios apostrophe uikeyboardtype
source share
1 answer

release the keyboard and become the first responder again. In my code, I created an IBOutlet for the * tf text field. It worked.

 - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([string isEqualToString:@" "]) { self.tf.keyboardType = UIKeyboardTypeNumberPad; [textField resignFirstResponder]; [self.tf becomeFirstResponder]; } return YES; } 
+10
source share

All Articles