0

I am trying to center a popover in my iOS 10 ipad application.

I have created a popover segue from one view to another in my storyboard. I have set the 'Kind' of segue to 'Popover':

enter image description here

Then in prepareForSegue:

if ([[segue identifier] isEqualToString:@"PopoverSegue"]) {
  UIPopoverPresentationController *popoverController = segue.destinationViewController.popoverPresentationController;
  popoverController.sourceView = self.view;
  popoverController.sourceRect = self.view.bounds;
}

However popoverController is nil. Looking around it looks like others had success doing this:

How to change the size of a popover

Any ideas why I cannot get a hold of the popoverPresentationController in prepareForSegue when the popover segue was created in a storyboard?

Community
  • 1
  • 1
lostintranslation
  • 23,756
  • 50
  • 159
  • 262
  • I do not know your architecture, but it can be that missing navaigationController. Try this: segue.destinationViewController.navigationController.popoverPresentationController or segue.destinationViewController.popoverPresentationController.navigationController – Ramis Mar 16 '17 at 07:55
  • I don't embed my viewcontroller in a navigation controller. So there is no navigation controller. As far as I understand the popoverPresentationController should be in the view that is embedded in the popover. Just for fun I embedded my view in a navigation controller to see if that made a difference, which it did not. Bug in iOS 10? Not supported in iOS 10? – lostintranslation Mar 16 '17 at 15:36

1 Answers1

0

Your segue kind is Popover. If you changed it to Present as Popover, then you should see value in destinationViewController.popoverPresentationController property. You may need to explicitly enable trait variations in the storyboard properties for Present as Popover to show up as an option.

user2962393
  • 1,083
  • 9
  • 12