iPhone AlertView 文本字段键盘不可见

发布于 2024-12-17 04:07:40 字数 591 浏览 0 评论 0原文

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

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

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

但是在我想要的不同视图中做同样的事情。因此,我没有使用 UITableView 控制器,而是将其设为 UIViewController,以便我可以在视图底部添加工具栏。

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

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

有什么想法吗?

更新:

键盘被隐藏的原因是因为我在显示警报后关闭了模态视图控制器。由于某种原因,我猜它也会关闭键盘。刚刚重新安排了顺序,现在效果很好......

I have an alert view with a uitextfield added as a subview.

In my uitableview controller the keyboard shows fine.

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

However in a different view I wanted to do the same thing. So instead of using a UITableView Controller I made it a UIViewController so that I could add a toolbar at the bottom of the view.

But when I display the UIAlertView the keyboard is hidden. I'm thinking it's behind the view because the alert view moves up to make room for the keyboard.

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

Any ideas?

UPDATE:

The reason the keyboard was being hidden was because I was dismissing a modalviewcontroller after showing the alert. For some reason it would dismiss the keyboard also I guess. Just rearranged the order an fit works fine now...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦情居士 2024-12-24 04:07:40

尝试实现 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 文档
UIAlertViewDelegate 文档< /a>

Try implementing the didPresentAlertView: method and inside set the text field to firstResponder like so:

- (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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文