Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertController is Crashed (iPad)

To keep it device independent, rather use it as shown in the snippet below. This code will return nil for popoverPresentationController on an iPhone / compact size device, so you can safely use it in universal projects.

if let popoverPresentationController = shareMenu.popoverPresentationController {
    popoverPresentationController.sourceView = self.view
    popoverPresentationController.sourceRect = sender.bounds
}
self.presentViewController(shareMenu, animated: true, completion: nil)

try this code:

shareMenu.popoverPresentationController.sourceView = self.view
shareMenu.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 1.0, 1.0)

self.presentViewController(shareMenu, animated: true, completion: nil)

Swift 4

popoverPresentationController.permittedArrowDirections = .init(rawValue: 0)
popoverPresentationController.sourceView = self.view
popoverPresentationController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)

reference: ActionSheet Popover on iPad in Swift

create popoverController :

let alertController = UIAlertController(title: nil, message: "Alert message.", preferredStyle: .actionSheet)
self.present(alertController, animated: true, completion: nil)

if you want show alert with indicator view should:

if let popoverController = alertController.popoverPresentationController {
    popoverController.barButtonItem = sender
}

with indicator

show alert in center:

if let popoverController = alertController.popoverPresentationController {
  popoverController.sourceView = self.view
  popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) 
}

center with indicator

center no indicator:

if let popoverController = alertController.popoverPresentationController {
  popoverController.sourceView = self.view
  popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
  popoverController.permittedArrowDirections = []
}

center no indicator