UIKeyboardTypeNumberPad在iPad上不显示数字键盘。相反,它显示UIKeyboardTypeNumbersAndPunctuation键盘。
我是否遗漏了某些东西,或者是否已将其从iPad OS中移除?
感谢您的指导!
答案 0 :(得分:14)
我认为iPad上的iPhoneOS 3.2目前不支持此功能
引用UITextInputTraits头文件:
//
// 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).
//
答案 1 :(得分:8)
在您的标题文件(.h文件)中添加UITextFieldDelegate
txtfield_name.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
txtfield_name.delegate=self;
然后添加此方法
- (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;
}
答案 2 :(得分:2)
我知道这个问题已经暂停了很长一段时间,但这可能会帮助那些人。
您可以尝试实施此https://github.com/azu/NumericKeypad。编码器实现了他自己的数字键盘购买子类化UITextField