I want to show a popover on iPad as soon as my view loads having as source a button on the top right corner. The popover displays properly on button tap, but I'm having trouble finding a way to display it without the button tap, when the page first loads. Is this possible?
This is what I have:
func displayOptions(sourceButton: UIBarButtonItem)
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
if let popoverController = actionSheet.popoverPresentationController {
var rect = CGRect(x: 0, y: 0, width: 0, height: 0)
popoverController.barButtonItem = sourceButton
popoverController.sourceRect = rect
popoverController.permittedArrowDirections = .up
}
viewController.present(actionSheet, animated: true, completion: nil)
}
This code works properly on button tap, but the app crashes if I try to call this function from viewDidLoad or viewDidAppear:
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.
sourceView.UIAlertControllermust have atitle, amessageor an action to display.