Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dismiss a popover from parent in swift

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..

like image 491
LIH Avatar asked Jun 08 '15 11:06

LIH


1 Answers

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)
like image 142
Nirav Gadhiya Avatar answered Sep 22 '22 15:09

Nirav Gadhiya