UIKeyboardTypeNumberPad在iPad上不显示数字键盘.而是显示UIKeyboardTypeNumbersAndPunctuation键盘.
有没有我遗失的东西,或者是否已将其从iPad OS中移除?
谢谢你的指导!
我相信目前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). //
添加UITextFieldDelegate
您的头文件(.h文件)
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; }