0

I'm making a custom keyboard for iOS8, and I managed to do my own return key, using [self.textDocumentProxy insertText:@"\n"];

But that also dismiss the keyboard, which I don't want. I need the keyboard to stay on.

I tried to make my UIInputViewController delegate of UItextField to access the textfieldShouldEndEditing delegate method, but it's never fired. It seems like it is impossible access the currently edited UITextfield from the custom keyboard.

Is there any way to prevent the keyboard to dismiss when my return key is pressed ?

Cheers,

Andrew
  • 15,357
  • 6
  • 66
  • 101
Mx83
  • 51
  • 5
  • In which app does this happen? I've tested the same (calling insertText:@"\n") in the Calendar app in Simulator, and it works as expected. On single-line fields such as "Title", the keyboard is dismissed, whereas on multi-line fields such as "Notes", a new line is entered and the keyboard stays on. I am not able to test on a device at the moment unfortunately. – Dev Kanchen Sep 03 '14 at 19:04
  • I got the same result as yours. But what I want is a way to act like the user press enter but without dismissing the keyboard. For example, in Google, the keyboard type the text "Hello World", then the user press the enter key on my keyboard. It then needs to act like user pressed enter (So google load his page for search results for "Hello World") BUT the keyboard needs to stay on. And insertText:@"\n" automatically dismiss the keyboard. – Mx83 Sep 03 '14 at 22:57
  • You cannot override the default behavior of the keyboard. If the default iOS keyboard appears or dismisses in certain scenarios, then your keyboard will also invariably appear or dismiss in the same scenarios. You CANNOT change this - this is by design. – Dev Kanchen Sep 04 '14 at 03:52
  • On the other hand, if you have your own app, you can definitely control the appearance/dismissal behavior of BOTH the default keyboard and ANY custom keyboard (not just yours). Any app you make and any keyboard you make are both completely independent and have clearly demarcated aspects of the text-input behavior they CAN control (such as, the keyboard can control the language of entry, auto-correction, etc, while the app can control any accessory views that are added) and what they CANNOT (the app cannot add keys to the keyboard, the keyboard cannot change the appear/dismiss behavior) – Dev Kanchen Sep 04 '14 at 03:54
  • Ok thanks. So there is no way to prevent its dismiss. That's so annoying :/ – Mx83 Sep 04 '14 at 04:25
  • I added this as a more detailed answer. Please mark the answer as accepted if it answered your question completely. – Dev Kanchen Sep 04 '14 at 06:24

1 Answers1

3

Showing/Dismissing a keyboard - whether default iOS, or a custom extension - is application-controlled behavior (hence the delegate methods in UITextField), and CANNOT be controlled by the keyboard itself.

The keyboard and the host application run in isolated, sandboxed processes and cannot directly control each other. The methods for the application/keyboard to interact with each other are ONLY the ones exposed by Apple, and these at the moment, do not include a way for the keyboard extension to control when it is shown or hidden.

Dev Kanchen
  • 2,332
  • 3
  • 28
  • 40