9

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.

Janaka
  • 2,505
  • 4
  • 33
  • 57

3 Answers3

17

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;

PengOne
  • 48,188
  • 17
  • 130
  • 149
5

Try using this........

 [textField becomeFirstResponder];
 textField.keyboardType = UIKeyboardTypeNumberPad;
Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
  • this will set the textField keyboard to number pad permanently. What I want is to show normal keyboard with numeric option selected. After typing the apartment number he has to type road, town also – Janaka Jun 04 '11 at 05:03
1

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

Legolas
  • 12,145
  • 12
  • 79
  • 132
  • @Jhaliya: It's not clear to me that the questioner wants a number pad for the text field since he wants the user to enter an entire address, e.g. @"123 Fake St"; – PengOne Jun 04 '11 at 05:03
  • this will set the textField keyboard to number pad permanently. What I want is to show normal keyboard with numeric option selected. After typing the apartment number he has to type road, town also. I am not sure this is the answer i am looking for ... – Janaka Jun 04 '11 at 05:06
  • @Janaka @PengOne: i missed that point, i think should go with the solution suggested by @PengOne. – Jhaliya - Praveen Sharma Jun 04 '11 at 05:22
  • @PengOne: Lol. Nice One !! FTW ! – Legolas Jun 04 '11 at 11:48