[iPhone] NumberPad with return key?

I have a text field that I want to restrict to numeric entry only. The obvious thing seems to be to set textField.keyboardType = UIKeyboardTypeNumberPad, which pops up a modal numeric keyboard as expected. However, the numeric keyboard doesn't have a return key, so it gets stuck on the screen. How do I handle this?

BTW, I know I could use UIKeyboardTypeNumbersAndPunctuation, but the text field should really only have numbers in it, not punctuation.

Mac Mini, Mac OS X (10.5.4)

Posted on Jul 7, 2008 9:36 PM

Reply
10 replies

Jul 7, 2008 9:41 PM in response to Brandon Fosdick

There's no way to add a Done button to the number pad. In my apps, I've gotten around this by placing a Done button in the right corner of the controller's navigation item; the button is connected to an action that makes the text field resignFirstResponder. (This occasionally means juggling with another button, like a "Save" button, but I think that the movement of the keyboard provides enough of a transition that the swap isn't jarring to the user.)

Jul 9, 2008 11:03 AM in response to Brandon Fosdick

There's no way in the SDK. I know the jailbreakers have discovered a UIKeyboard class that can be used to control the keyboard, but I don't know how it works, and you're not supposed to use undocumented APIs in App Store programs.

As for your navigation bar problem, perhaps you could use a more appropriate verb than "Done" for your keyboard. "Save"? "Next"? I don't know exactly what you're doing with it, but that's something to think about. (And for that matter, another thing to think about is dropping the separate edit mode entirely--I've found that they're not really needed that often. Notes doesn't have one, for instance.)

Jul 10, 2008 10:45 PM in response to Brent Royal-Gordon

On the screen in question my app is displaying a set of fields using a tableview. So far its a pretty standard interface...tap the plus button to go to edit mode then tap a row and a modal keyboard pops up. I'm thinking maybe hiding the keyboard if the user taps the same row again (in lieu of a Done button), but I'm not sure how obvious that will be to the first time user.

I like the idea of getting rid of the tap for edit mode, but I'm not sure how that would work here. ATM I swap out the UITableViewCells for UITextFields upon entering edit mode. I could do that on response to a selection message, but would the row automatically get redrawn when I make the swap? Maybe I can force a redraw somehow. I'll have to play with it. Thanks for the idea.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

[iPhone] NumberPad with return key?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.