8

I have a third party keyboard that currently contains a UISearchBar(that is first responder on start) and the user is able to search for content (i.e. gifs) to be able to copy, paste, send to friends, etc.

In theory, after entering text in the bar and pressing search, the user should be able to enter text in the application's actual UITextView (i.e. the message field in the messages app) but for some reason this doesn't work and although typing works, nothing actually appears. I have tried searchBar.resignFirstResponder(), self.becomeFirstResponder() and many combinations of .endEditing(true) to no avail. I know it is possible to do this as apps like Giffy do it but I can't figure it out for the life of me. Any help would be greatly appreciated.

cyril
  • 3,020
  • 6
  • 36
  • 61
  • I'm sorry, I guess I didn't quite understand your problem. Is the issue that when you press return, your entered text in your search bar isn't occurring in your TextField? Or that isn't switching the first responder to the textView? – MQLN Oct 26 '15 at 18:02
  • I have a search bar in my third party keyboard. When I finish typing in the search bar, I can't seem to type anywhere else other than in the keyboard's search bar. So if I'm in the Notes app, I can't type in it anymore until I exit the keyboard completely. – cyril Oct 26 '15 at 18:04
  • Oh weird, so while the keyboard is open, you can't make anything else become a first responder? – MQLN Oct 26 '15 at 18:05
  • Yup unless I take off the search bar or don't tap to try and type in it – cyril Oct 26 '15 at 18:06
  • That sounds really annoying. Bummer. Have you tried messing around with it's delegate? (i.e. is it set up properly?) Are you using a library or existing git project for this keyboard? – MQLN Oct 26 '15 at 18:08
  • Nope just my little old project on a little old private repo. Just create a new project, add a keyboard extension, add a text view or search bar to it and see – cyril Oct 26 '15 at 18:33

1 Answers1

1

Keyboard extensions with built-in search bars usually implement their search bar as a UILabel, adding custom text handling behavior that modifies the text property of the label based on user input.

Ben Pious
  • 4,765
  • 2
  • 22
  • 34
  • How certain are you of that? Is there no other way of doing this? – cyril Oct 26 '15 at 22:09
  • Pretty much 100% certain. The fundamental issue, as I understand it, is that the text field you were editing prior is outside of the keyboard process, so there's no way to address it to send it the message to become first responder again. I think the easiest way to determine if there are any keyboards in the app store that can do this is to see if any of them support tap and hold to move the cursor around, and if it has the same UI as system text fields. – Ben Pious Oct 27 '15 at 03:38
  • Check out the Giffage app (Free) on the Appstore. When the keyboard launches, you enter text in the search bar (there's a cursor). As soon as you search for an GIF, you can enter a space or return sequence in the original app. So something happens in between that lets you do that. But what? :o – cyril Oct 27 '15 at 23:23
  • You've misunderstood, I don't mean that the *existence* of a cursor implies that it is a system text field, I mean that being able to move the cursor with the same gestures as a "real" textfield implies this. The Giffage search bar is a UILabel, with ~100% certainty -- tapping and holding on it doesn't bring up a magnifying glass, and double tapping doesn't show an editing popover. Another observation: you can't switch focus from the search bar to the prior text field (the real one, inside the app itself) by tapping on it. – Ben Pious Oct 27 '15 at 23:45
  • I get what you mean, no worries :) I'm not arguing the nature of the search field, just how to switch the focus as it seems to be doing automatically as soon as the search button is pressed and then the user swipes up – cyril Oct 28 '15 at 01:51
  • That is the simplest part of the fake-textfield scheme to implement. As the implementer of the keyboard, you control whether pressing keys on the keyboard actually results in input to the "real" textfield. In your text handling code, simply add behavior to switch the object that receives output, from your `textDocumentProxy` to your search field, and then whenever the user presses search or swipes up, simply switch the output object to the "real" textfield. – Ben Pious Oct 29 '15 at 16:55