美文网首页
在iPad上使用UIAlertController控件

在iPad上使用UIAlertController控件

作者: 醒目_c75f | 来源:发表于2020-07-01 14:24 被阅读0次

- (IBAction)btnAction:(id)sender {

    UIAlertController* alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleAlert)];

        [alertVCaddAction:[UIAlertActionactionWithTitle:@"打开相册"style:(UIAlertActionStyleDefault) handler:^(UIAlertAction*_Nonnullaction) {

        }]];

        [alertVCaddAction:[UIAlertActionactionWithTitle:@"打开摄像机"style:(UIAlertActionStyleDefault) handler:^(UIAlertAction*_Nonnullaction) {

        }]];

        [alertVCaddAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {

        }]];

    //    alertVC.popoverPresentationController.sourceView = self.btn;

    //    alertVC.popoverPresentationController.sourceRect = self.btn.bounds;

        [self presentViewController:alertVC animated:YES completion:nil];

}

发现网上说的添加popoverPresentationController的sourceView和sourceRect 或者barbuttonItem都不行,只要UIAlertControllerStyle为UIAlertControllerStyleActionSheet,都会崩溃,获取不到popoverPresentationController,只需要把UIAlertControllerStyle改为UIAlertControllerStyleAlert即可.

相关文章

网友评论

      本文标题:在iPad上使用UIAlertController控件

      本文链接:https://www.haomeiwen.com/subject/mvscqktx.html