当前位置:  开发笔记 > 编程语言 > 正文

UIKeyboardTypeNumberPad - 在iPad上显示numbes?

如何解决《UIKeyboardTypeNumberPad-在iPad上显示numbes?》经验,为你挑选了2个好方法。

UIKeyboardTypeNumberPad在iPad上不显示数字键盘.而是显示UIKeyboardTypeNumbersAndPunctuation键盘.

有没有我遗失的东西,或者是否已将其从iPad OS中移除?

谢谢你的指导!



1> Dustin Howet..:

我相信目前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).
//


他们可能只是自己实现了它.

2> Hector..:

添加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;
}

推荐阅读
手机用户2402852387
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有