如何在UITextField中最初在默认键盘中显示数字

时间:2011-06-04 04:33:14

标签: iphone keyboard numbers uitextfield

在我的iPhone应用程序中,我有一个地址行1字段。我已经为此分配了默认键盘。但最有可能的第1行字段将以公寓号开头。

我想知道如何在此字段的默认键盘中显示数字。

3 个答案:

答案 0 :(得分:14)

您可能希望使用UIKeyboardTypeNumbersAndPunctuation,因为一旦输入街道号码,用户就可以返回按字母键盘(通过按键盘底部的“ABC”按钮)。如果使用数字键盘,则只能输入数字。

要在IB中执行此操作,请打开Inspector并选择此作为默认键盘。要以编程方式执行此操作,只需添加textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

即可

答案 1 :(得分:5)

尝试使用此........

 [textField becomeFirstResponder];
 textField.keyboardType = UIKeyboardTypeNumberPad;

答案 2 :(得分:2)

将textField.inputView设置为

    textField.inputView = nil;
    [textField setKeyboardType:UIKeyboardTypeNumberPad];

按照本教程设置“完成”按钮!

http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key