xcode 专注于 UITextField
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6153561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
focus on UITextField
提问by Gavin
I am doing a login page, whereby if the user press the login button without filling up the username/password, an alertview will pop up. How do I focus on the textfield and bring up the keyboard accordingly after the user dismiss the alertview?
我正在做一个登录页面,如果用户在没有填写用户名/密码的情况下按下登录按钮,则会弹出一个警报视图。在用户关闭警报视图后,如何专注于文本字段并相应地调出键盘?
What is the method to call to set focus on a particular UITextField? Thanks!
调用以将焦点设置在特定 UITextField 上的方法是什么?谢谢!
回答by Mark Granoff
Make sure your UIAlertView's delegate is your view controller (self), and in the implementation of the UIAlertView delegate method alertView:clickedButtonAtIndex:
, call [usernameTextField becomeFirstResponder]
. Easy! (Make sure your view controller class adopts the UIAlertViewDelegate
protocol.)
确保您的 UIAlertView 的委托是您的视图控制器(自己),并且在 UIAlertView 委托方法的实现中alertView:clickedButtonAtIndex:
,调用[usernameTextField becomeFirstResponder]
. 简单!(确保您的视图控制器类采用该UIAlertViewDelegate
协议。)
回答by taskinoor
[myTextField becomeFirstResponder];
回答by Konstantin Chugalinskiy
You should use a code [mytextField becomeFirstResponder];
in your – alertView:clickedButtonAtIndex:
delegate method.
您应该[mytextField becomeFirstResponder];
在– alertView:clickedButtonAtIndex:
委托方法中使用代码。