您的位置:首页 > 产品设计 > UI/UE

iOS8下,使用UIAlertControllerStyleActionSheet时发生崩溃,怎么办?

2015-09-19 16:43 465 查看
代码是这样的:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[alertController addAction:[UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

}]];

UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {

}];

[alertController addAction:deleteAction];

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


然而却发生了崩溃:

Your application has presented a UIAlertController (<UIAlertController: 0x7af36380>) 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.


你还需要指定PopoverPresentationController的源视图和位置,所以,在上面的代码结尾增加以下代码就可以了:

UIPopoverPresentationController *popover = alertController.popoverPresentationController;

if (popover) {

popover.sourceView = imageView;
popover.sourceRect = imageView.bounds;
popover.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: