UIPopoverController in iOS 8

1.8k Views Asked by At

Everybody says UIPopoverController work on iOS 8.

But if i test my app in iPhone simulator it getting crashed and log says:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.'

This code works fine on iPad simulator.

My Development Target set to 8.4

UIViewController* viewController = [[UIViewController alloc] initWithNibName:@"StyleMenu" bundle:nil];
    self.stylePopover = [[UIPopoverController alloc] initWithContentViewController:viewController];
    self.stylePopover.popoverContentSize = CGSizeMake(250,200);
    [self.stylePopover presentPopoverFromBarButtonItem:styleBarButton
                               permittedArrowDirections:UIPopoverArrowDirectionUp
                                               animated:YES];

any help would be appreciated.

3

There are 3 best solutions below

3
Soberman On BEST ANSWER

Yes, it is possible starting from iOS8. I have already gave answer to similar question and even implemented a useful class to work with popovers on iPhone and even put some custom elements there, such as UITableView, WKWebView, you name it.
You can check out my answer and link to class here: https://stackoverflow.com/a/30418212/2924920

5
Ashley Mills On

UIPopoverController is unavailable on the iPhone. Use the new popoverPresentationController property of your viewController instead

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIPopoverPresentationController_class/index.html

MYViewController * myViewController = [[MYViewController alloc] init];
myViewController.modalPresentationStyle = UIModalPresentationPopover;
myViewController.popoverPresentationController.sourceView = button;
myViewController.popoverPresentationController.sourceRect = button.bounds;
[self presentViewController: myViewController animated: YES completion: nil];
1
SilkyPantsDan On

Unfortunately the UIPopoverController is exclusive for iPads, as per the Apple documentation

Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.

Also a possible duplicate from this question? UIPopoverController for iphone not working?