Search code examples
iosinterface-buildersegueuipopovercontroller

Get UIPopoverController reference in prepareForSegue?


I have selected Present as Popover in Interface Builder for my StoryBoard Segue.

enter image description here

How can I get reference to UIPopoverController in prepareForSegue?

I tried like this, but it not goes inside the if statement.

    if segue is UIStoryboardPopoverSegue {
        let popoverSegue = segue as UIStoryboardPopoverSegue
        simpleTableViewController.popoverController = popoverSegue.popoverController
    }

UPDATE

If you need popovercontroller, just to dismiss it, then the way to dismiss an adaptive view controller is:

self.dismissViewControllerAnimated(true, completion: nil)

Solution

  • You shouldn't check the type of the segue, rather you should check the segue identifier.

    if segue.identifier == "popover" {
        let popoverSegue = segue as UIStoryboardPopoverSegue
        simpleTableViewController.popoverController = popoverSegue.popoverController
    }