Force keyboard to show up via button (iOS)

僤鯓⒐⒋嵵緔 提交于 2019-12-01 06:07:39

From the iPhone Application Programming Guide

However, you can programmatically display the keyboard for an editable text view by calling that view’s becomeFirstResponder method. Calling this method makes the target view the first responder and begins the editing process just as if the user had tapped on the view.

So to show the keyboard programmatically,

[textView becomeFirstResponder];

However, the keyboard will never show if the textView is not editable.

The purpose of showing the keyboard is to allow editing. I assume you just don't want the keyboard to appear when the user taps the text view. In this case, you can enable editable programmatically when the button is tapped.

-(IBAction) yourButtonClick
{
     myText.editable = YES;
     [myText becomeFirstResponder];

}

Then in the UITextViewDelegate, disable editable when the user finishes editing.

- (void)textViewDidEndEditing:(UITextView *)textView {
  textView.editable = NO;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!