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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:08:29  来源:igfitidea点击:

focus on UITextField

xcodefocusuitextfield

提问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 UIAlertViewDelegateprotocol.)

确保您的 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:委托方法中使用代码。