UIKeyboardTypeNumberPad在iPad上不顯示數字鍵盤。相反,它顯示了UIKeyboardTypeNumbersAndPunctuation鍵盤。UIKeyboardTypeNumberPad - 僅顯示iPad上的麻煩?
有什麼我很想念,或者這是從iPad操作系統中刪除?
感謝您的指導!
UIKeyboardTypeNumberPad在iPad上不顯示數字鍵盤。相反,它顯示了UIKeyboardTypeNumbersAndPunctuation鍵盤。UIKeyboardTypeNumberPad - 僅顯示iPad上的麻煩?
有什麼我很想念,或者這是從iPad操作系統中刪除?
感謝您的指導!
我認爲,這是當前不支持的iPhoneOS 3.2在iPad上
引述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).
//
我知道這個問題已經不活躍了相當長一段時間,但是這可能會幫助那裏的人。
您可以嘗試執行這一個https://github.com/azu/NumericKeypad。編碼器實現了自己的數字鍵盤買子類的UITextField
謝謝,這很酷 – Justin 2012-05-29 17:29:28
在頭文件中添加UITextFieldDelegate
(h文件)
txtfield_name.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
txtfield_name.delegate=self;
再加入此方法
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString *validRegEx [email protected]"^[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;
}
這不會做什麼問題(只顯示在iPad上的數字),而是使用默認鍵盤(與字母等),並限制輸入,只允許數字。 – lnafziger 2014-05-30 04:00:04
這並不是說它被刪除了,而是它從來沒有擺在首位。你必須創建自己的鍵盤才能做到這一點。請參閱:[如何從iOS應用上的自定義鍵盤檢索擊鍵?](http://stackoverflow.com/a/13351686/937822) – lnafziger 2014-05-30 04:01:20