Search code examples
iosios8uipopovercontrolleruiactionsheetuialertcontroller

UIActionSheet from Popover with iOS8 GM


Anyone is getting this message while trying to show UIActionSheet from popover?

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

Previously to the GM I used some workaround for converting the UIActionSheet to UIAlertController and this is working fine. However it seems that Apple tried to solve the UIActionSheet issues and I didn't want to use my workaround - but it seems that I have no choice...


Solution

  • To support iPad, include this code:

    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)