来自Popover的UIActionSheet与iOS8 GM

Tom*_*led 47 uiactionsheet uipopovercontroller ios ios8 uialertcontroller

在尝试从popover显示UIActionSheet时,是否有人收到此消息?

您的应用程序提供了样式UIAlertControllerStyleActionSheet的UIAlertController().具有此样式的UIAlertController的modalPresentationStyle是UIModalPresentationPopover.您必须通过警报控制器的popoverPresentationController为此弹出窗口提供位置信息.您必须提供sourceView和sourceRect或barButtonItem.如果在显示警报控制器时未知此信息,则可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供该信息.

在GM之前,我使用了一些解决方法将UIActionSheet转换为UIAlertController,这很好用.然而,似乎Apple试图解决UIActionSheet问题,我不想使用我的解决方法 - 但似乎我别无选择......

小智 105

要支持iPad,请包含以下代码:

alertView.popoverPresentationController?.sourceView = self.view
alertView.popoverPresentationController?.sourceRect = self.view.bounds
// this is the center of the screen currently but it can be any point in the view

self.presentViewController(alertView, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

  • 什么是shareMenu?它是alertVc吗? (2认同)

Stu*_*ner 11

如果您在用户对a中的单元格进行选择后显示操作表UITableView.我发现这个效果很好:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Directions" 
                                                               message:@"Select mode of transportation:"
                                                        preferredStyle:UIAlertControllerStyleActionSheet];
alert.popoverPresentationController.sourceView = cell;
alert.popoverPresentationController.sourceRect = cell.bounds;
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
//...
[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)


Ang*_*han 7

您需要提供popoverPresentationControlleriPad支持.在此,您指定barButtonItemsourceView.这个另一个线程可以帮到你:Swift UIAlertController - ActionSheet iPad iOS8崩溃