Reputation: 1618
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.
Upvotes: 1
Views: 1878
Reputation: 2596
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
Upvotes: 2
Reputation: 571
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?
Upvotes: 0
Reputation: 53231
UIPopoverController
is unavailable on the iPhone. Use the new popoverPresentationController
property of your viewController instead
MYViewController * myViewController = [[MYViewController alloc] init];
myViewController.modalPresentationStyle = UIModalPresentationPopover;
myViewController.popoverPresentationController.sourceView = button;
myViewController.popoverPresentationController.sourceRect = button.bounds;
[self presentViewController: myViewController animated: YES completion: nil];
Upvotes: 2