在iPad上使用UIAlertController控件
- (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即可.