UIAlertController在ipad上运行崩溃

匿名 (未验证) 提交于 2019-12-03 00:39:02

当使用UIAlertController的

UIAlertControllerStyleActionSheet

时在ipad上运行会崩溃,报以下的错误:

意思就是没有设置UIAlertController这个弹出窗口的位置信息,可以通过下面的方式解决,

alertSheetVc.popoverPresentationController.sourceView = self.bgScrollView; 

alertSheetVc.popoverPresentationController.sourceRect = view.frame;

prepareForPopoverPresentation方法 来设置UIAlertController在当前页面上的位置信息,设置后的显示效果与 iPhone是有区别的不是在屏幕的中间位置弹出而是在你所设置的位置弹出:如下图的界面效果

UIAlertController *alertSheetVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];     alertSheetVc.popoverPresentationController.sourceView = self.bgScrollView;          alertSheetVc.popoverPresentationController.sourceRect =  view.frame;          UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {              }];     UIAlertAction *albumAction = [UIAlertAction actionWithTitle:@"去相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {         [self pushTZImagePickerController];     }];     UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {         [self takePhoto];     }];     [alertSheetVc addAction:cameraAction];     [alertSheetVc addAction:albumAction];     [alertSheetVc addAction:cancelAction];     [self presentViewController:alertSheetVc animated:YES completion:nil]; 

原文:https://www.cnblogs.com/Rong-Shengcom/p/9268493.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!