如何在UIAlertView中使文本字段"成为第一响应者"

Jac*_*ies 7 iphone objective-c uialertview ipad ios

我在UIAlertView中有两个文本字段.我希望第二个成为第一个响应者,以便用户不必点击它.显示警报视图后,我有以下代码:

[textField becomeFirstResponder];
Run Code Online (Sandbox Code Playgroud)

唯一的问题是它不起作用.第一个文本字段中包含了typer.有任何想法吗?谢谢你的帮助.

Tra*_* M. 13

尝试将焦点设置到UIAlertView中的密码字段时我遇到了同样的问题(我预先填充了用户名).我不得不使用委托方法:

- (void)didPresentAlertView:(UIAlertView *)alertView {
    UITextField *textField = [alertView textFieldAtIndex:0];
    [textField becomeFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)

如果我在willPresentAlertView上尝试它或者当我创建alertView时,它只能在didPresentAlertView上运行.我希望这有帮助.