How to get reference to UIPopoverController when using adaptive segue?

前端 未结 3 630
别跟我提以往
别跟我提以往 2021-02-07 10:00

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

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


        
相关标签:
3条回答
  • 2021-02-07 10:37

    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.

    0 讨论(0)
  • 2021-02-07 10:50

    This may not be the most foolproof way to do it but you could check the popoverPresentationController property on your destination view controller. From there you can configure the popover anchor and such.

    Check the "Configuring a Popover for Display" section of the UIPopoverPresentationController doc. (Not sure if we're allow to link to them at this point, are we?)

    Note too that now we're talking about UIPopover*Presentation*Controllers, not UIPopoverControllers. It's a little confusing...

    0 讨论(0)
  • 2021-02-07 10:53

    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.

    0 讨论(0)
提交回复
热议问题