开发者

Dismiss a number pad-style keyboard without adding Done key

开发者 https://www.devze.com 2023-03-20 12:41 出处:网络
There is no Done button on a Number Pad-type keyboard. I开发者_如何学C don\'t want to add a custom Done button, but how do I dismiss the keyboard?You could add a UINavigationBar/UIToolBar with a done

There is no Done button on a Number Pad-type keyboard. I开发者_如何学C don't want to add a custom Done button, but how do I dismiss the keyboard?


You could add a UINavigationBar/UIToolBar with a done button(a UIBarButtonItem), and make the textField/textView resignFirstResponder on the done button's action.

You can add the UINavigationBar/UIToolBar as inputAccessoryView of textField/textView.

textField.inputAccessoryView = aNavBarWithDoneButton;

Edit: Availability iOS (3.2 and later)


The simplest solution is to add a new button somewhere in your UI that calls resignFirstResponder on your UITextField (or whatever) when tapped. Putting this in a toolbar is problematic on iPhone because toolbars are typically at the bottom of the screen and obscured by the keyboard.

A slightly more complex solution is to put an invisible UIView behind all of your other tappable UI elements. Any taps not handled by your existing UI will go to this new view, which can call resignFirstResponder on your text field.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消