简体   繁体   中英

How to correctly start a popover segue from a custom uitableviewcell using the storyboard

So how do you correctly setup a popover segue using the storyboard when the button opening it is inside a custom prototype cell within a table view?

  1. It should work both on iphone and ipad
  2. It should have the correct position and anchor on ipad

I think the most elegant solution is the following:

Create a segue from the button as usual to the appropriate ViewController

Open the segue and set the anchor to the table view (dragging from the circle to the view).

In prepare for segue add the following:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    UIViewController *vc = (UIViewController *)segue.destinationViewController;
    UIPopoverPresentationController *ppc = vc.popoverPresentationController;
    UIButton *button = (UIButton *)sender;
    ppc.sourceRect = button.frame;
    ppc.sourceView = button.superview;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM