【问题标题】:iPhone AlertView Text Field Keyboard not visibleiPhone AlertView 文本字段键盘不可见
【发布时间】:2011-11-19 17:34:17
【问题描述】:

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

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

但是,从不同的角度来看,我想做同样的事情。因此,我没有使用 UITableView 控制器,而是将其设置为 UIViewController,这样我就可以在视图底部添加一个工具栏。

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

有什么想法吗?

更新:

键盘被隐藏的原因是我在显示警报后关闭了 modalviewcontroller。出于某种原因,我猜它也会关闭键盘。刚刚重新安排了合适的顺序,现在可以正常工作了...

【问题讨论】:

    标签: iphone objective-c keyboard


    【解决方案1】:

    尝试实现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

    【讨论】:

    • 效果很好!比延迟更好...谢谢
    猜你喜欢
    • 1970-01-01
    • 2017-11-15
    • 2011-01-19
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多