2010-04-08 39 views
17

UIKeyboardTypeNumberPad在iPad上不顯示數字鍵盤。相反,它顯示了UIKeyboardTypeNumbersAndPunctuation鍵盤。UIKeyboardTypeNumberPad - 僅顯示iPad上的麻煩?

有什麼我很想念,或者這是從iPad操作系統中刪除?

感謝您的指導!

+1

這並不是說它被刪除了,而是它從來沒有擺在首位。你必須創建自己的鍵盤才能做到這一點。請參閱:[如何從iOS應用上的自定義鍵盤檢索擊鍵?](http://stackoverflow.com/a/13351686/937822) – lnafziger 2014-05-30 04:01:20

回答

13

我認爲,這是當前不支持的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). 
// 
+1

但是我看到它在彈出窗口中的iPad上完成。他們是如何做到的呢? – David 2011-08-25 04:12:53

+3

他們可能只是自己實施它。 – ceejayoz 2011-10-21 01:33:38

2

我知道這個問題已經不活躍了相當長一段時間,但是這可能會幫助那裏的人。

您可以嘗試執行這一個https://github.com/azu/NumericKeypad。編碼器實現了自己的數字鍵盤買子類的UITextField

+0

謝謝,這很酷 – Justin 2012-05-29 17:29:28

8

在頭文件中添加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; 
} 
+1

這不會做什麼問題(只顯示在iPad上的數字),而是使用默認鍵盤(與字母等),並限制輸入,只允許數字。 – lnafziger 2014-05-30 04:00:04