问题描述
我有一个 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];
解决方法
这看起来很奇怪。
但我认为问题在于您正在调用 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