限制键盘只有 iPad 中的数字

Restricting the keyboard to have numbers only in iPad

在我的应用程序中,我有不同类型的输入,包括字母数字、数字、电子邮件等 UITextField.In iPhone 我可以使用相同的代码成功使用所需的 keyboards.But,当我们使用 UIKeyboardTypeNumbersAndPunctuations/UIKeyboardTypeDecimalPad 时,iPad 无法限制键盘中的数字。你能告诉我如何在 iPad 中使用 objective C 来实现这一点吗?

非常感谢您...

我最终得到了以下解决方案。这里我限制键盘只能接收数字输入。

if(textField.keyboardType == UIKeyboardTypeNumbersAndPunctuation)
    {
        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;
    }

从 Stack overflow only.Thanks 中获得了这段代码的很多代码。再次找不到 link。