简体   繁体   English

以编程方式在 iPhone 应用程序上显示键盘

[英]Programmatically show the keyboard on iPhone app

I have a view with only one UITextView that is used to enter a value.我有一个只有一个 UITextView 用于输入值的视图。 I want that when the view shows, the textview becomes the first responder (that's the easy part) and also the default keyboard shows up.我希望当视图显示时,textview 成为第一响应者(这是简单的部分),并且默认键盘也会出现。 I tried searching for this in speca but to no avail.我尝试在 speca 中搜索此内容,但无济于事。 There are many posts on how to dismiss the keyboard, but what I want is to show the keyboard w/o waiting for user to touch my textview.有很多关于如何关闭键盘的帖子,但我想要的是显示键盘而不等待用户触摸我的 textview。

Just setting the text field to firstResponder should do the trick. 只需将文本字段设置为firstResponder即可解决问题。

Inside your -viewDidLoad : -viewDidLoad内部:

[myTextField becomeFirstResponder];

Swift: Swift:

In the viewDidLoad:在 viewDidLoad 中:

textView.becomeFirstResponder()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM