I have a view controller that's presented in a popover using a storyboard segue.
In the presenting view controller, I had the following code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let svc = segue.destinationViewController as? SettingsViewController {
svc.popoverPresentationController?.delegate = self
}
}
However, it turns out that the presented view controller, even though it appears as a popover, has a modalPresentationStyle
of '.Modal
, and hence a nil
popoverPresentationController
. Weird!
So, I updated the code as follows:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let svc = segue.destinationViewController as? SettingsViewController {
svc.modalPresentationStyle = .Popover
svc.popoverPresentationController?.delegate = self
}
}
The svc.popoverPresentationController
delegate is now set OK, but if the popover is dismissed by the user tapping outside, none of the UIPopoverPresentationControllerDelegate
delegate methods (e.g. popoverPresentationControllerShouldDismissPopover
are called. What am I missing?
svc.modalPresentationStyle = .Popover
). Worth checking though! – Ashley Millssvc.popoverPresentationController
non-nil at that time? Else, it would silently not set the delegate. – Tobi Nary