【问题标题】:Why doesn't keyboard show when I make a UITextField within a UIAlertView become the first responder?当我使 UIAlertView 中的 UITextField 成为第一响应者时,为什么键盘不显示?
【发布时间】:2011-07-14 18:22:09
【问题描述】:

我有一个弹出的警报视图,其中包含一个文本字段,我希望该文本字段成为第一响应者并立即显示键盘。

当我使用 [summaryField becomeFirstResponder];我在文本字段中看到一个闪烁的光标,但没有弹出键盘。但是,如果我不将文本设置为第一响应者,而是在警报显示时单击其中的内容,则键盘会弹出。

关于文本字段如何在不显示键盘的情况下成为第一响应者的任何想法?我猜这与作为子视图添加到警报视图的文本字段有关,但我不知道究竟是什么问题。我的代码在下面,没有“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];

【问题讨论】:

    标签: objective-c ios xcode uitextfield uialertview


    【解决方案1】:

    UIAlertViewDelegate willPresentAlertView: 方法中尝试[textField becomeFirstResponder]

    【讨论】:

    • 太棒了。我实际上不得不使用“didPresentAlertView”,但如果没有你的回答,我是不会明白的。谢谢!
    • 这在使用 Xcode6 构建时似乎不再起作用,即使在部署到 iOS 7 设备时也是如此。
    猜你喜欢
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    相关资源
    最近更新 更多