UIAlertController 按钮不可见

问题描述

我有一个 Objective C 项目,想向用户显示一些警报,在某些 iPad 上,UIAlertController 按钮不可见,我在下面附上了一张图片。 有人遇到过这样的问题吗?有什么解决方法吗?

设备详情 iOS 14.4 iPad Air 2

使用的示例代码

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@“Alert” message:@“Message” preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@“YES” style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
            
           
        }];
        UIAlertAction *noAction = [UIAlertAction actionWithTitle:@“NO” style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
        }];
        [alert addAction:yesAction];
        [alert addAction:noAction];
        [alert show];

图片

enter image description here

解决方法

这看起来很奇怪。
但我认为问题在于您正在调用 show 方法。
您需要“presentViewController”,因为它不再是 UIAlertView' 而是 UIAlertViewController

请使用我的代码片段。

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        //button click event
                    }];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancel];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];

为了更深入的研究,我推荐这个article

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...