UIAlertController在ipad上运行崩溃( UIAlertController (<UIAlertController: 0x1099a7800>) of style UIAlertCo...

 

 

当使用UIAlertController的

UIAlertControllerStyleActionSheet

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

 reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x1099a7800>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem.  If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.

 

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

alertSheetVc.popoverPresentationController.sourceView = self.bgScrollView; 

alertSheetVc.popoverPresentationController.sourceRect = view.frame;

 或者是通过实现 UIPopoverPresentationControllerDelegate的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值