There are two UIViewConrollers in my Storyboard: MainViewController and SecondViewController. I'm going to show SecondViewController as a popover when user taps a button called Show Popover:
//MainViewController
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "GoToSecondViewControllerSegue"
{
var vc = segue.destinationViewController as! SecondViewController
var controller = vc.popoverPresentationController
if controller != nil
{
controller?.delegate = self
vc.inputTextDelegate = "I'm a popover!"
}
}
}
func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
println("done")
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle
{
return .None
}
//SecondViewController
@IBAction func dismissPopover(sender: UIButton) {
dismissViewControllerAnimated(true, completion: nil)
//This dismisses the popover but does not notify the MainViewConroller
}
The anchor of segue is connected to a button:
Now I have two problems:
When I tap the cancel button inside the popover it dismisses the popover but does not trigger popoverPresentationControllerDidDismissPopover
inside the MainViewController
How can I pass data from the SecondViewController to the MainViewController, text value of a UITextView for example.
Taps outside of the popover's contents automatically dismiss the popover.
Or, more simply, just call iOS's delegate method manually when you dismiss the popover manually.
dismissViewControllerAnimated(true, completion: nil)
popoverPresentationController?.delegate?.popoverPresentationControllerDidDismissPopover?(popoverPresentationController!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With