There are two UIViewConrollers in my Storyboard: MainViewController and SecondViewController. I\'m going to show S
I have the same problem and find the answer in Apple API.
About the function popoverPresentationControllerDidDismissPopover, they 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.
So we have to do it ourselves.
You can choice a block or a delegate like @Maysam did which is more heavy. Here's my way to use a block FYI.
Let's just focus on key functions.
class SecondViewController: UIViewController {
var dismissPopover: (() -> Void)?
deinit {
if let block = self.dismissPopover {
block()
}
}
@IBAction func dismissPopover(sender: UIButton) {
dismissViewControllerAnimated(true, completion: nil)
//This dismisses the popover but does not notify the MainViewConroller
}
}
I made a block, and call it well secondVC 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()
// call your method...
}
}
}
func DoSomething(text: String) {
//Do whatever you want
println(text)
}
}
Set up the block in prepareForSegue: method, and Done.