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开发者_StackOverflow中文版)];
[summaryField setBackgroundColor:[UIColor whiteColor]];
[titleAlert addSubview:summaryField];
[titleAlert show];
[titleAlert release];
[summaryField release];
try [textField becomeFirstResponder]
in UIAlertViewDelegate
willPresentAlertView:
method.
精彩评论