Ios – How to dismiss a popover from parent in swift

delegatesiosswift

I am new to iOS and swift. I'm trying to show a popover. I have managed to show a popover but the problem is I need to dismiss it from the parent.

I can dismiss the popover from the ViewController itself using this code

self.dismissViewControllerAnimated(true, completion: nil)

But I need to do this from the parent view controller.

I have done this so far. On button click
performSegueWithIdentifier("bookingPopOverSegue", sender: self)

on prepareForSegue,

if segue.identifier == "bookingPopOverSegue" {

        var bookingViewController = segue.destinationViewController as! BookingViewController
        var passthroughViews: [AnyObject] = self.timeSlotButtons
        passthroughViews.append(self.scrollView)
        bookingViewController.popoverPresentationController?.passthroughViews = passthroughViews
    }

Any idea on how to do this? Any help would be appreciated..

Best Answer

Just call dismiss method using parent's presentedViewController property, like ....

self.presentedViewController.dismissViewControllerAnimated(true, completion: nil)

For Swift 3.0

self.presentedViewController?.dismiss(animated: true, completion: nil)