Call made to adaptivePresentationStyleForPresentationController even for iPad sim

1.2k views Asked by At

I have a viewcontroller implementing the UIPopoverPresentationControllerDelegate method of:

adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle 

As far as I understood, this should be called only for compact size such as iPhone 6, but not for iPad. But in one project, it is called even for iPad, and as a result, I don't get a popover but the full screen modal thing.

I can't see what could be causing this to happen. I looked into another project with roughly the same setup and confirmed that this method doesn't get called during iPad sim (only iphone).

Anyone else experience this?

2

There are 2 answers

0
kawingkelvin On

I found out what's wrong. I picked the wrong func during code completion, the correct delegate method I meant to use is:

adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle

not

adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle 
0
Kurt Anderson On

Depending on your iOS level, you should be using adaptivePresentationStyleForPresentationController: traitCollection:

I'm using this method (returning .None) and it's working on all devices I've tested so far.

In the Apple documentation for adaptivePresentationStyleForPresentationController: it says this:

In iOS 8.3 and later, use the adaptivePresentationStyleForPresentationController:traitCollection: method to handle all trait changes instead of this method. If you do not implement that method, you can use this method to change the presentation style when transitioning to a horizontally compact environment.

Edit For my target iOS of 8, I'm actually using both of these methods. pre-8.3 won't use the one with traitCollection: