【问题标题】:inputAcessoryView being displayed with UIAlertControllerinputAcessoryView 与 UIAlertController 一起显示
【发布时间】:2015-07-23 14:41:00
【问题描述】:

我已经覆盖了 UIViewController 中的 -inputAccessoryView: 方法,该方法返回一个视图,该视图显示在键盘顶部,当在 viewController 的视图上编辑 UITextField 时显示该视图。

-(UIView *)inputAccessoryView;

我还展示了来自 viewController 的 UIAlertController。

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Save Profile" message:@"You have made changes to your profile. Do you want to save them?" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //Code to save the profile.
    }]];
[self presentViewController:alert animated:YES completion:nil];

如您所见,我没有向 UIAlertController 添加任何文本字段。

奇怪的是,当 UIAlertController 出现时 inputAcessoryView 出现在屏幕底部。

这是一个错误,还是我忽略了什么?

【问题讨论】:

  • 我也面临同样的问题。

标签: ios objective-c uiviewcontroller uialertcontroller presentviewcontroller


【解决方案1】:

将您的输入附件视图重命名为 inputAccessoryView 以外的名称。 例如键盘附件视图。

然后添加下面一行

self.m_textFieldName.inputAccessoryView = [self keyboardInputAccessoryView];

这解决了我的问题。

【讨论】:

    【解决方案2】:

    请勿使用名称“inputAccessoryView”

    这将解决..!

        - (UIView *)CustominputAccessoryView {
        if (!keyboardinputAccessoryView) {
            CGRect accessFrame = CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 40.0);
            keyboardinputAccessoryView = [[UIView alloc] initWithFrame:accessFrame];
            keyboardinputAccessoryView.backgroundColor = [UIColor  colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.6];
            UIButton *compButton = [UIButton buttonWithType:UIButtonTypeCustom];
            compButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-60, 0.0, 50, 40.0);
            [compButton setTitle: @"Done" forState:UIControlStateNormal];
            compButton.titleLabel.textColor = [UIColor blueColor];
            [compButton setTitleColor:self.view.tintColor forState:UIControlStateNormal];
            [compButton addTarget:self action:@selector(completeCurrentWord:)
                 forControlEvents:UIControlEventTouchUpInside];
            [keyboardinputAccessoryView addSubview:compButton];
        }
        return keyboardinputAccessoryView;
    }
    

    keyboardinputAccessoryView 只是一个 UIView

    @property (readonly, retain) UIView *keyboardinputAccessoryView;
    

    然后将'CustominputAccessoryView'作为你的textField的inputAccessoryView

    - (void)textFieldDidBeginEditing:(UITextField *)textField {
     textField.inputAccessoryView = [self CustominputAccessoryView];
    }
    

    【讨论】:

      【解决方案3】:

      遇到同样的问题,你可以试试

      textFirld.resignFirstResponder()
      

      在展示 AlertViewController 之前。

      它对我有用。

      【讨论】:

        【解决方案4】:

        你有 UITextField 的属性,比如 inputAccessoryView,所以它已经过时了。如果可能的话

        只需更改视图的名称

        -(UIView *)inputAccessoryView;
        

        某个名字

        -(UIView *)alertDisplayView;
        

        这将解决..!确切地说,我不明白你为什么使用名称 inputAccessoryView..!

        希望对你有所帮助..!

        【讨论】:

        • 输入附件视图正在返回以显示在视图控制器视图上的另一个 UITextField 的键盘顶部。
        • 不要在任何方法中使用名称 inputAccessoryView,因为它可能会导致这些问题。因此,如果不使用它,我认为 inputAccessoryView 不会显示在任何文本字段中。
        • 重点是,我需要在当前UIVIewController中显示inputAccessoryView。问题是为什么在呈现 UIAlertController 时会显示 inputAcessoryView。我不确定你是否理解我的问题。
        猜你喜欢
        • 1970-01-01
        • 2014-12-14
        • 1970-01-01
        • 2016-01-09
        • 2023-04-02
        • 1970-01-01
        • 2015-10-24
        • 2018-05-21
        相关资源
        最近更新 更多