3

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

I want to know how to know when the user switches from the alphabet side of the Default keyboard to the Numeric side.

The reason I want that is that I want to keep the numeric side when user changes from one textfield to the next, if the last thing they wrote is a number.

And I can't use the numbersAndPunctuation keyboard type as a whole because it doesn't have the ability to change to Emoji, which I still need to be able to. But if I knew when they switched, I would be able to start at the NumbersAndPunctuation and then when the user switched I would be able to change keyboard type to default, so the User would be able to switch to Emoji.

Either that or the ability to start the default keyboard on the numbers side. If that's possible that would be a solution aswell.

Any help would be appreciated :)

Community
  • 1
  • 1
Hafax
  • 369
  • 2
  • 14
  • I think Your best option would be simply operate with last entered symbol. If User entered digits or point, commas - then You know that user used numeric side. – Guntis Treulands Sep 29 '14 at 08:20

3 Answers3

2

Here is my contribution to the "detecting" the keyboardType. Essentially, there is no API to get what you want. https://stackoverflow.com/a/26095686/2719509

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

  1. The user types text into the [original] textField, changes the keyboard, wants to go to the next keyboard
  2. Create a [new]text field, populate it with the text the user entered, position it in exactly the same position of the text field where the user was working
  3. Move the [original]textField to the position of the [next]textField, remove the text entered and replace it with the text of the[next]textField. Make the [next]textField.hidden = YES until the user goes to the [next next]textField.
  4. Repeat 2 & 3.

Don't use animations while moving textFields around.

What's the trick: to preserve the state of the keyboard keep the textField constant and make the user believe he is writing in different textFields.

Hope it helps.

Community
  • 1
  • 1
JoelEsli
  • 451
  • 3
  • 8
  • This "hack" might actually work. I'll try it out and accept the answer if it solves my problem. Thanks :) – Hafax Sep 29 '14 at 10:02
0

add if (textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation) in your textfield delegates

0

Try this, it will help you detect the last character, using this you can identify keyboard type. (presently which type of keyboard is opened?)

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

It's working for me.. Hope this will help you.

mattsson
  • 1,329
  • 1
  • 14
  • 30
Urmi
  • 344
  • 1
  • 14