8

I have a custom inputView for a particular textfield, and it works well. However, I cannot discern how to dismiss the view and get the regular keyboard back. (I have a SWAP button right next to the TextField.) I tried setting the textfield's inputView to nil, but that did nothing.

I do not need a full custom keyboard, but I need more than an Accessory view above the keyboard, which is why I am trying this route. I need about 20 custom buttons in addition to the regular keyboard, and I do not like the idea of a huge Accessory view taking up so much space.

I also would rather not require the user to initially install a full custom keyboard before being able to use the app.

Thank you very much for any suggestions.

Craig Smith
  • 1,063
  • 2
  • 11
  • 21

2 Answers2

11

I think you will probably have to do this:

  1. Call resignFirstResponder on the UITextField
  2. After the animation finishes, set your inputView to nil
  3. Call becomeFirstResponder on the text field

The keyboard animation duration is sent in the userInfo dictionary on the keyboard presentation notifications.

bdrell
  • 194
  • 2
  • 5
  • Thank you very much! It also turned out to be easy to catch the notification so that the user can just swap the keyboard and the custom input in and out at will. Perfect! – Craig Smith May 24 '15 at 04:54
9

In addition to the accepted answer, you can use reloadInputViews() (and this is less likely to suffer any animation glitches resulting from the resignFirstResponder, becomeFirstResponder calls):

  1. yourTextField.inputView = nil;
  2. yourTextField.reloadInputViews();

Here's more info in the Apple's Docs.

adamup
  • 1,508
  • 19
  • 29