我正在尝试显示一个固定在工具栏按钮上的UIAlertControllerStyleActionSheet。我在网上搜索过,发现我必须这样做:
alertController.popoverPresentationController.barButtonItem = myButton;
然而这对我不起作用。 UIAlertController在iPad上的iPhone上显示。居中于窗户的中间。
这是我的代码:
// create action sheet
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"test title" message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
// Delete Button
UIAlertAction *actionDelete = [UIAlertAction
actionWithTitle:@"button"
style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
// Delete
}];
// Cancel Button
UIAlertAction *actionCancel = [UIAlertAction
actionWithTitle:@"Avbryt"
style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// Cancel code
}];
// Add Cancel action
[alertController addAction:actionCancel];
[alertController addAction:actionDelete];
// show action sheet
alertController.popoverPresentationController.barButtonItem = self.downloadAllButton;
alertController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
[alertController setModalPresentationStyle:UIModalPresentationPopover];
[self presentViewController:alertController animated:YES completion:nil];
顺便说一下,我在Documentpicker的Document Provider扩展中这样做。所以UIAlertControllerStyleActionSheet已经处于模态视图中。我猜这是我的问题,但我无法弄清楚如何为iPad改变它。这让我抓狂!请帮助!!
此致 马库斯