Reputation: 33967
Starting with a single view controller app template. I added a button on the main view controller and second view controller, then I attached the button to the second view controller with a storyboard segue presented as a popover.
Sadly, the segue sent into the prepareForSegue:sender:
method is not a UIStoryboardPopoverSegue
. Is it possible to attach delegates to a storyboard segue's popover?
class ViewController: UIViewController, UIPopoverControllerDelegate {
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let popoverSegue = segue as? UIStoryboardPopoverSegue {
popoverSegue.popoverController.delegate = self
}
}
func popoverControllerDidDismissPopover(popoverController: UIPopoverController) {
println("dismissed")
}
}
Upvotes: 1
Views: 938
Reputation: 56
Had the same issue recently. In iOS 8, you can access the UIPopoverPresentationController and set the UIPopoverPresentationControllerDelegate (rather than the UIPopoverController and -Delegate) through the popoverPresentationController
of the destinationViewController, using this code:
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if let controller = segue.destinationViewController as? UIViewController {
controller.popoverPresentationController.delegate = self
}
}
Upvotes: 4