Reputation: 741
After selecting text in a textview/textfield in an app (Messages, for example), you can select Share
from the popup menu to share the text. Since you were editing text at the time you selected/shared, the keyboard is visible. Once you have selected an share target app, the keyboard will continue to be visible when the target app's extension appears. I need to dismiss this keyboard so that other elements on the screen are visible and accessible. In my case, I have no editable fields (e.g. textField/textView) in the custom view controller that appears in the extension. (i.e. to become firstResponder)
The usual solutions that do not work:
[self.view endEditing:YES]
- No subview in my view is firstResponder[self.textView resignFirstResponder]
- No textView/textField in my view (https://stackoverflow.com/a/28119785/650365)[[[UIApplication sharedApplication] keyWindow] endEditing:YES]
- sharedApplication
is unavailable in share extensions[theViewController setEditing:NO animated:YES]
Hacky solution that does work (from https://stackoverflow.com/a/34299724/650365):
becomeFirstResponder
.resignFirstResponder
on that same textField.How can I dismiss the keyboard in a Share Extension on iPhone without adding extra textField/textViews?
Upvotes: 1
Views: 659
Reputation: 2198
Your ShareViewController
inherits from SLComposeServiceViewController
. That is what causes the keyboard to be presented, it has a textView
.
Replace that SLComposeServiceViewController
with a simple UIViewController
and the keyboard will not appear.
Upvotes: 0