How to know when a user has changed a value from Alphabet to Numeric iOS

I want to know what this guy is asking how to detect when the default iOS keyboard type switches from text to numbers

I want to know how to know when the user switches from the keyboard's default alphabet side to the numeric side.

The reason I want is because I want to keep the numeric side when the user changes from one textbox to another if the last thing they wrote is a number.

And I can't use the numbersAndPunctuation keyboard type in general because it doesn't have the option to go to Emoji, which I still need. But if I knew when they switch, I could start with NumbersAndPunctuation, and then when the user switched, I could change the default keyboard type so that the User can switch to Emoji.

Either that or the ability to launch the default keyboard on the numbers side. If possible, this will also be a solution.

Any help would be appreciated :)


source to share

3 answers

Here is my contribution to "detecting" the keyboard type. Basically, there is no API to get what you want. / ...

How to get the functionality you want using the current API.

  • User enters text in [original] textField, changes keyboard, wants to move to next keyboard.
  • Create a text field [new], fill it with the user's text and enter it in the exact same position of the text field where the user was working.
  • Move the [original] textField to the [next] textField position, remove the entered text, and replace its text with [next] textField. Do [next] textField.hidden = YES until the user navigates to [next next] textField.
  • Repeat 2 and 3.

Do not use animations when moving text boxes around.

What a trick: To preserve the keyboard state, keep a constant textField and make the user think they are writing in different text fields.

Hope it helps.



add a if (textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation)

textbox in your delegates



Try this, it will help you detect the last character, using this you can detect the keyboard type. (currently, what type of keyboard opens?)

- (BOOL)textField:(UITextField *)field shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)characters{        
    if([characters rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]].location == NSNotFound){
    }else if([characters rangeOfCharacterFromSet:[[NSCharacterSet letterCharacterSet] invertedSet]].location == NSNotFound){
    return YES;


This works for me .. Hope it helps you.



All Articles