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);
This segue is relevant only for view controllers embedded inside a UISplitViewController object. With this segue, a split view controller replaces its second child view controller (the detail controller) with the new content. Most other view controllers present the new content modally.
The starting point of a segue is the button, table row, or gesture recognizer that initiates the segue. The end point of a segue is the view controller you want to display. A segue always presents a new view controller, but you can also use an unwind segue to dismiss a view controller.
The starting point of a segue is the button, table row, or gesture recognizer that initiates the segue. The end point of a segue is the view controller you want to display. A segue always presents a new view controller, but you can also use an unwind segue to dismiss a view controller. You do not need to trigger segues programmatically.
Because segues are configured from storyboards, both view controllers involved in the segue must be in the same storyboard. During a segue, UIKit calls methods of the current view controller to give you opportunities to affect the outcome of the segue.
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.
Elaborating on Joey's answer, which led me to what seems the new manner of achieving what we used to do with UIPopoverController.
This code in prepareForSegue:Sender:
UIViewController *destination = segue.destinationViewController;
UIPopoverPresentationController *ppc = destination.popoverPresentationController;
ppc.delegate = self;
is a simple way to successfully set your view controller as delegate of a UIPopoverPresentationController much the same as you are probably used to doing with the old UIPopoverController
.
And, of course, while you are at it you'll probably add:
[destination setPreferredContentSize:CGSizeMake(300.00f, 300.00f)];
if you were in the habit of setting UIPopoverController size here as well.
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