UIActionSheet from Popover with iOS8 GM
To support iPad, include this code:
alertView.popoverPresentationController?.sourceView = self.viewalertView.popoverPresentationController?.sourceRect = self.view.bounds// this is the center of the screen currently but it can be any point in the viewself.presentViewController(alertView, animated: true, completion: nil)
If you are presenting the action sheet after the user makes a selection on a cell within a UITableView
. I found that this works decently well:
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];
You need to provide popoverPresentationController
for iPad support. In this, you either specify barButtonItem
or sourceView
. This another thread may help you: Swift UIAlertController - ActionSheet iPad iOS8 Crashes