2

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
Daniele Bernardini
  • 1,516
  • 1
  • 12
  • 29

1 Answers1

5

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;
}
Daniele Bernardini
  • 1,516
  • 1
  • 12
  • 29
  • Does this work when the segue starts within the storyboard? I think I recall an issue with this solution in that case, since the anchor must be first specified within the storyboard, and I think changing it programmatically in this fashion was not successful. – SAHM May 11 '16 at 04:23
  • I'm sorry, I was using a container view controller, which confused the situation for me. This did work. Thank you. – SAHM May 11 '16 at 05:24