Disable the numeric keypad without adding a Finish button

There is no Done button on a keyboard with a numeric keypad. I don’t want to add a custom Done button, but how do I cancel the keyboard?

+4
source share
2 answers

You can add a UINavigationBar / UIToolBar using the made button (UIBarButtonItem) and make textField / textView resignFirstResponder on the action of the made button.

You can add a UINavigationBar / UIToolBar as inputAccessoryView textField / textView.

textField.inputAccessoryView = aNavBarWithDoneButton; 

Edit: Availability of iOS (3.2 and later)

+4
source

The easiest solution is to add a new button somewhere in your user interface that calls resignFirstResponder on your UITextField (or any other) when clicked. Putting this on the toolbar is problematic on the iPhone because the toolbars are usually located at the bottom of the screen and are closed by the keyboard.

A slightly more complicated solution is to place an invisible UIView behind all of your other displayed interface elements. Any taps that are not handled by your existing interface will go into this new view, which can call resignFirstResponder in the text box.

If none of these sound appeals, perhaps you should expand your question to include the type of behavior you want.

+2
source

All Articles