Mark Petereit
Mark Petereit

Reputation: 341

Default iPad AlphaNumeric Keyboard into Numeric Mode

I have a UITextField for users to enter their street address. I have Keyboard appropriately set to Default for the field.

Since most people's street addresses start with a number, I would like it to default to numeric mode, as if the user had already pressed the .?123 key. That way, they can immediately begin entering the numeric portion of their address, and as soon as they press the spacebar, it will immediately shift back to alpha.

Is this possible?

Upvotes: 6

Views: 4576

Answers (1)

Marcus Adams
Marcus Adams

Reputation: 53830

There is currently no setting or options that does this. You must do it programmatically by watching for space bar input with notifications via UITextFieldTextDidChangeNotification or with the textField:shouldChangeCharactersInRange:replacementString: delegate method and then switching the keyboard.

iOS used to switch to the alphabet keyboard after a space bar even when using UIKeyboardTypeNumbersAndPunctuation. This was fixed in 5.0.

When you switch the keyboard type for a field, you're really just saying which keyboard to use next time it is displayed. If the keyboard is already being displayed, switching the type doesn't change it. So, hide the keyboard, switch the type, then show it again:

[textField1 resignFirstResponder];
[textField1.keyboardType = UIKeyboardTypeAlphabet];
[textField1 becomeFirstResponder];

Upvotes: 1

Related Questions