iPhone AlertView文本字段键盘不可见

时间:2011-11-18 18:44:15

标签: iphone objective-c keyboard

我有一个警报视图,其中uitextfield被添加为子视图。

在我的uitableview控制器中,键盘显示正常。

http://i301.photobucket.com/albums/nn76/hackmodford/c804bd91.jpg

然而,在另一种观点中,我想做同样的事情。因此,我没有使用UITableView控制器,而是使其成为UIViewController,以便我可以在视图的底部添加工具栏。

但是当我显示UIAlertView时,键盘被隐藏了。我认为它在视图后面,因为警报视图向上移动以便为键盘腾出空间。

http://i301.photobucket.com/albums/nn76/hackmodford/5680aaa2.jpg

有什么想法吗?

更新:

键盘被隐藏的原因是因为我在显示警告后解雇了一个modalviewcontroller。出于某种原因,我猜也会解雇键盘。刚刚重新安排了合适的顺序......

1 个答案:

答案 0 :(得分:5)

尝试实施didPresentAlertView:方法并在内部将文本字段设置为firstResponder,如下所示:

- (IBAction)someActionThatTriggersAnAlertView:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"TITLE" message:@"MESSAGE" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done", nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *someTextField = [alert textFieldAtIndex:0];
    someTextField.keyboardType = UIKeyboardTypeAlphabet;
    someTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
    someTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    [alert show];
    [alert release];
}

#pragma mark - UIAlertViewDelegate Methods

- (void)didPresentAlertView:(UIAlertView *)alertView {
    [[alertView textFieldAtIndex:0] becomeFirstResponder];
}

UIAlertView Documentation
UIAlertViewDelegate Documentation

相关问题