I have the same problem and find the answer in the Apple API .
About the popoverPresentationControllerDidDismissPopover function, say The popover presentation controller calls this method after dismissing the popover to let you know that it is no longer onscreen. The presentation controller calls this method only in response to user actions. It does not call this method if you dismiss the popover programmatically. The popover presentation controller calls this method after dismissing the popover to let you know that it is no longer onscreen. The presentation controller calls this method only in response to user actions. It does not call this method if you dismiss the popover programmatically.
So we have to do it ourselves.
You can choose a block or delegate like @Maysam, which was heavier. Here is my way to use the FYI block.
Let's just focus on key features.
class SecondViewController: UIViewController { var dismissPopover: (() -> Void)? deinit { if let block = self.dismissPopover { block() } } @IBAction func dismissPopover(sender: UIButton) { dismissViewControllerAnimated(true, completion: nil)
I made a block and called it wellVin deinit.
class MainViewController: UIViewController, UIPopoverPresentationControllerDelegate, MyDelegate { override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "GoToSecondViewControllerSegue" { var vc = segue.destinationViewController as! SecondViewController vc..dismissPopover = { [unowned self] () in self.DoSomehing()
Configure the block in the prepareForSegue: method and Done file.
source share