iOS8下,使用UIAlertControllerStyleActionSheet时发生崩溃,怎么办?
2015-09-19 16:43
465 查看
代码是这样的:
然而却发生了崩溃:
你还需要指定PopoverPresentationController的源视图和位置,所以,在上面的代码结尾增加以下代码就可以了:
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; }
相关文章推荐
- execute、executeQuery和executeUpdate之间的区别
- iOS8下,UIImagePickerController的popoverPresentationController为空,要怎么获取?
- UITableView/UITabBarController/可视化编程/自动布局
- iOS 使用UIDocumentInteractionController类打开文件
- java学习笔记图形程序设计及GUI应用小结(1)
- UEditor和CKEditor配置上传图片,视频,附件
- 客户端GUI程序开发漫谈
- UIView 中autoresizingMask的属性
- 点击UITableView的cell展开收缩
- UIScrollView pagingEnabled自定义翻页宽度
- 多线程工具之NSOperationQueue
- 进行水印的添加
- PHP中include和require的区别详解
- 基于信号量与P/V操作同步机制的读者/写者问题的设计与实现 (写者优先)
- UIScrollView总结
- UIView总结:
- java.util.Queue用法
- Scala深入浅出实战经典:39,ListBuffer、ArrayBuffer、Queue、Stack操作代码实战
- C#串口控制舵机、arduino源码 及C#源码及界面
- Distinct Subsequences