Search code examples
iosobjective-csegueuipopovercontrolleruistoryboardsegue

How to get reference to UIPopoverController when using adaptive segue?


In my iOS 7 app, I detected if a segue was a popover via this check in prepareForSegue:

if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]])

But now that I am using adaptive segues, the Present as Popover segue is no longer returning true in the above check. This is because segue is no longer a UIStoryboardPopoverSegue, instead it is a UIStoryboardPopoverPresentationSegue. However, one cannot simply add the Presentation word because that's not defined.

What is the appropriate way to detect when the segue is a popover from an adaptive segue, as opposed to a full screen modal presentation?

And, how do you get a reference to the popover for iOS 8? The following is what I'm doing for iOS 7 but again because it's not a UIStoryboardPopoverSegue this will cause a crash.

UIPopoverController *popover = ((UIStoryboardPopoverSegue *)segue).popoverController;
popover.popoverContentSize = CGSizeMake(380, 1000);

Solution

  • There actually was no need to get a reference to the popover for iOS 8. You can access the popoverPresentationController directly in the view controller that's presented. Then use dismissViewControllerAnimated to dismiss the view controller. You can set the popover content size directly in the view controller that's being presented via preferredContentSize. I found I had no need to obtain a reference in prepareForSegue, at least when running on iOS 8. iOS 7 is a different story.