18

UIKeyboardTypeNumberPad doesn't display a number pad on the iPad. Instead, it shows the UIKeyboardTypeNumbersAndPunctuation keyboard.

Is there something I'm missing, or has this been removed from the iPad OS?

Thanks for your guidance!

Daddy
  • 9,045
  • 7
  • 69
  • 98
  • 1
    It isn't that it was removed, but rather that it was never there in the first place. You have to create your own keyboard to do this. See: [How do I retrieve keystrokes from a custom keyboard on an iOS app?](http://stackoverflow.com/a/13351686/937822) – lnafziger May 30 '14 at 04:01

3 Answers3

14

I believe that this is not currently supported in iPhoneOS 3.2 on the iPad

To quote the UITextInputTraits header file:

//
// UIKeyboardType
//
// Requests that a particular keyboard type be displayed when a text widget
// becomes first responder. 
// Note: Some keyboard/input methods types may not support every variant. 
// In such cases, the input method will make a best effort to find a close 
// match to the requested type (e.g. displaying UIKeyboardTypeNumbersAndPunctuation 
// type if UIKeyboardTypeNumberPad is not supported).
//
Dustin Howett
  • 1,635
  • 11
  • 13
8

add UITextFieldDelegate in your header file (.h file)

txtfield_name.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
txtfield_name.delegate=self;

then add this method

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

 NSString *validRegEx =@"^[0-9]*$"; //change this regular expression as your requirement
 NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", validRegEx];
 BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:string];
 if (myStringMatchesRegEx)
        return YES;
 else
        return NO;
}
Hector
  • 3,909
  • 2
  • 30
  • 46
  • 1
    This doesn't do what the question asks (to show just the numbers on an iPad), but instead uses the default keyboard (with letters, etc.) and restricts the input so that only numbers are allowed. – lnafziger May 30 '14 at 04:00
2

I know this question has been inactive for quite a while, but this might help somebody out there.

You can try implementing this one https://github.com/azu/NumericKeypad. The coder implemented his own number pad buy subclassing the UITextField

acecapades
  • 893
  • 12
  • 23