Clicky

iOS Dev Nugget 175 Displaying a Popover in iPhone App

.

Need to run a code review on your codebase? Hire me

You can show a view controller in a popover by setting modalPresentationStyle to UIModalPresentationPopover. This works nicely in iPad apps, but as noted in the documentation:

In a horizontally compact environment, this option behaves the same as UIModalPresentationFullScreen.

So the view controller will be displayed in full screen. If you want the view controller to be displayed as a popover anyway, you can override this behavior by setting implementing UIPopoverPresentationControllerDelegate. E.g.

//Create theViewControllerToPresent and configure it...
theViewControllerToPresent.delegate = self;
[vc presentViewController:theViewControllerToPresent animated:YES completion:nil];

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationNone;
}

This will force the presentation style to not be adapted to "full-screen mode" on the iPhone.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues