iOS how to combine keyboard with a text field and show them together?

437 views Asked by At

I'm trying to create a text entry widget for my app. I found XCDFormInputAccessoryView example on Github and modified it so the text field is located on the accessory view. This, in theory, allows me to call the text entry widget from any part of my app.

To clarify: there is no textField in any of the view controllers for which I want to present this widget.

However, I cannot seem to figure out how to present the text entry widget. I tried:

[self.inputAccessoryView becomeFirstResponder];
[self.inputAccessoryView.textField becomeFirstResponder];
[[UIApplication sharedApplication] sendAction:@selector(becomeFirstResponder) to:nil from:nil forEvent:nil];
[[UIApplication sharedApplication] sendAction:@selector(becomeFirstResponder) to:self.inputAccessoryView.textField from:nil forEvent:nil];

How can I make the keyboard to show IF the text field for which it is shown is an accessory to the keyboard itself?

enter image description here

1

There are 1 answers

0
Wain On BEST ANSWER

Your current attempt doesn't work because the text field in the accessory view isn't in the view hierarchy when you try to make it the first responder.

What you need to do is something like have a 'dummy' text field that is part of the view hierarchy but which is off screen, so you can't see it but you can make it the first responder and then switch the first responder to your other text field once the keyboard is displayed.