强制键盘通过按钮显示(iOS) [英] Force keyboard to show up via button (iOS)

查看:147
本文介绍了强制键盘通过按钮显示(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITextView,我不想检查可编辑选项,如何通过按钮调用键盘?
此代码对我不起作用!

I have an UITextView and I don't want check editable option, how can call keyboard via a button? This code doesn't work for me!

-(IBAction) yourButtonClick
{
    [myTextView becomeFirstResponder];
    [self.view addSubview:myTextView]; 
}


推荐答案

来自iPhone应用程序编程指南

From the iPhone Application Programming Guide


但是,您可以通过调用该视图的$ b $以编程方式
显示键盘以显示可编辑的
文本视图b成为FirstResponder方法。调用
这种方法使目标查看
第一响应者并开始编辑
过程,就像用户在视图上点击了
一样。

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];

但是,如果textView不可编辑,键盘将永远不会显示。

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];

}

然后在UITextViewDelegate中,在用户完成编辑时禁用editable 。

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

- (void)textViewDidEndEditing:(UITextView *)textView {
  textView.editable = NO;
}

这篇关于强制键盘通过按钮显示(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆