0

I have a UITextView field meant to receive input from a keyboard.

But the standard keyboard not being adequate for my app, I built another one with the buttons and characters I need.

I would normally make use of the UITextViewDelegate protocol and things would work. But in this situation, how do I connect the UITextView field and my new keyboard? Is there a "best way to do it"?

Thanks in advance for any relevant information.

Michel
  • 10,303
  • 17
  • 82
  • 179

1 Answers1

1

Set your custom view as inputView of the UITextView.

// Edit: additional information:

Your custom keyboard will be a collection of buttons. You can add the same selector as target for all those buttons. Than your callback could be:

- (void) buttonTouched: (UIButton*) button
{
    myTextView.text = [myTextView.text stringByAppendingString: button.text];
}
calimarkus
  • 9,955
  • 2
  • 28
  • 48
  • Thanks a lot for this tip. Searching on the net for inputView and UITextView makes me think you definitely put me on the right track. Though I still have a lot of work to do before I get my UITextView actually getting input from my custom keyboard. Since I have never done that before, there are a lot of details I do not know how to handle in the process. Like how do I deal with the key events on the custom keyboard and other things. It would be nice to have a small and clear sample, but that I did not find yet. – Michel Mar 07 '12 at 08:20
  • I can see the logic here about the IBAction. I presume what you call: - (void) buttonTouched: (UIButton*) button; is the same as what I call: -(IBAction) kbdButtonHandle:(id)sender; in my custom keyboard class. Tell me if I am wrong. But how is declared myTextView in your example? Which I suppose points to the UITextView instance. Because the keyboard instance does not know about the UITextView instance (again tell me if I am wrong); I do not quite understand where the link is made. – Michel Mar 07 '12 at 11:26
  • 1
    You have to make it on your own. When you set the inputView (`myCustomKeyboard.inputView = myCustomKeyboard`), you could also set the textView in your keyboardClass. E.g.: `[myCustomKeyboard setTextView: theTextView];` – calimarkus Mar 07 '12 at 11:33
  • Thanks. I will try to find more info and experiment. I am not quite following this last comment, but maybe making my custom keyboard a subclass of UIView was already a mistake. – Michel Mar 07 '12 at 11:50
  • No its not a mistake. Just add a property to your keyboard class, where you can set a UITextView, which than will be used in your `kbdButtonHandle:`. Feel free to ask more questions. – calimarkus Mar 07 '12 at 14:10
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8646/discussion-between-michel-and-jaydee3) – Michel Mar 07 '12 at 16:54