Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickmeehan/1e59fd628f1340ffb9f65c329cd045b8 to your computer and use it in GitHub Desktop.
Save nickmeehan/1e59fd628f1340ffb9f65c329cd045b8 to your computer and use it in GitHub Desktop.
iPad ActionSheet Presentation - Bar Button Item No Cast
@IBAction func showDeleteActionSheet(_ sender: UIBarButtonItem) {
let alertController = UIAlertController(title: nil, message: "Alert message.", preferredStyle: .actionSheet)
let defaultAction = UIAlertAction(title: "Default", style: .default, handler: { (alert: UIAlertAction!) -> Void in
// Do some action here.
})
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (alert: UIAlertAction!) -> Void in
// Do some destructive action here.
})
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { (alert: UIAlertAction!) -> Void in
// Do something here upon cancellation.
})
alertController.addAction(defaultAction)
alertController.addAction(deleteAction)
alertController.addAction(cancelAction)
if let popoverController = alertController.popoverPresentationController {
popoverController.barButtonItem = sender
}
self.present(alertController, animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment