当我使 UIAlertView 中的 UITextField 成为第一响应者时,为什么键盘不显示?
我有一个弹出的警报视图,其中包含一个文本字段,我希望该文本字段成为第一响应者并立即显示键盘。
当我使用 [summaryField comeFirstResponder]; 时我在文本字段中看到一个闪烁的光标,但键盘没有弹出。但是,如果我不将文本设置为第一响应者,而是在警报显示时单击文本内部,键盘就会弹出。
关于文本字段如何在不显示键盘的情况下成为第一响应者有什么想法吗?我猜想这与将文本字段作为子视图添加到警报视图有关,但我不知道问题到底是什么。我的代码如下,没有“becomeFirstResponder”调用。
UIAlertView *titleAlert = [[UIAlertView alloc] initWithTitle:@"Enter title" message:@" "
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
summaryField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[summaryField setBackgroundColor:[UIColor whiteColor]];
[titleAlert addSubview:summaryField];
[titleAlert show];
[titleAlert release];
[summaryField release];
I have an alert view that pops up with a text field inside it, and I want the text field to become the first responder and show the keyboard immediately.
When I use [summaryField becomeFirstResponder]; I get a blinking cursor in the text field, but the keyboard does not pop up. However, if I don't make the text the first responder, and instead just click inside of it when the alert shows, the keyboard does pop up.
Any ideas on how a text field can become the first responder without showing the keyboard? I would guess it has something to do with the text field being added as a subview to the alert view, but I don't know what exactly the problem is. My code is below, without the "becomeFirstResponder" call.
UIAlertView *titleAlert = [[UIAlertView alloc] initWithTitle:@"Enter title" message:@" "
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
summaryField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[summaryField setBackgroundColor:[UIColor whiteColor]];
[titleAlert addSubview:summaryField];
[titleAlert show];
[titleAlert release];
[summaryField release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在
UIAlertViewDelegate
willPresentAlertView:
方法中使用[textFieldBecomeFirstResponder]
。try
[textField becomeFirstResponder]
inUIAlertViewDelegate
willPresentAlertView:
method.