Janaka
Janaka

Reputation: 2785

how to show numbers in the default keyboard initially for UITextField

In my iPhone application I have an address line 1 field. I have assigned the default keyboard to that. But most likely line 1 field will start with apartment number.

I want to know how to show numbers in the default keyboard initially for this field.

Upvotes: 10

Views: 11282

Answers (3)

PengOne
PengOne

Reputation: 48398

You may want to use UIKeyboardTypeNumbersAndPunctuation instead, since the user can then go back to the alphabetical keyboard (by pressing the "ABC" button on the bottom of the keyboard) once the street number is entered. If you use the numberPad, only numbers can be entered.

To do this in IB, open the Inspector and select this as the default keypad. To do this programmatically, just add textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

Upvotes: 19

Mehul Mistri
Mehul Mistri

Reputation: 15147

Try using this........

 [textField becomeFirstResponder];
 textField.keyboardType = UIKeyboardTypeNumberPad;

Upvotes: 5

Legolas
Legolas

Reputation: 12325

Set you textField.inputView as

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

Follow this tutorial for setting up a 'DONE' button !

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

Upvotes: 1

Related Questions