This is a bit too late out. But if someone else stumbles upon this question:
Solution
It is based on setting the anchor for the UIPopoverController programmatically. You still need to assign it to something (for example the "view") in storyboards if you are using storyboards, but the code will override that choice.
This can be performed rather simply by applying the following to your prepare(for: sender:) and also add the desired view the UIPopoverController should anchor to in the sender parameter of performSegue(withIdentifier: , sender:)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
else if segue.identifier == "openingHours" {
let vc = segue.destinationViewController
vc.preferredContentSize = CGSize(width: 200, height: 100)
vc?.popoverPresentationController?.delegate = self
// Remember to pass in the cell or whatever view you want it to be anchored to in performSegue(withIdentifier: "YourSegueID", sender: tableViewCell)
if let anchorView = sender as? UIView {
vc?.popoverPresentationController?.sourceView = anchorView
}
// If you want to anchor it to a UIBarButtonItem (in a nav bar for example use this), remove the code bellow if you are using a view:
else if let anchorView = sender as? UIBarButtonItem {
vc?.popoverPresentationController?.barButtonItem = anchorView
}
}
}