【发布时间】: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