I am trying to implement UIPopoverPresentationController
in my app to display tableViewController
. It works fine when app runs on an iPhone but crashes on an iPad.
The code that is the problem is:
- (void)soundsButtonHandler:(UIBarButtonItem *)barButtonItem {
IESoundsTableViewController *soundsTVC = (IESoundsTableViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"SoundsTableViewController"];
soundsTVC.baseSceneViewController = self;
soundsTVC.popoverPresentationController = [[UIPopoverPresentationController alloc] initWithPresentedViewController:soundsTVC presentingViewController:self];
soundsTVC.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:soundsTVC animated:YES completion:nil];
self.popoverPresentationController = soundsTVC.popoverPresentationController;
self.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
self.popoverPresentationController.barButtonItem = barButtonItem;
}
This works just fine on an iPhone & brings up the tableView modally with the usual vertical presentation.
However, it fails on an iPad with the following stack trace:
- objc_exception_throw ()
- -[UIPopoverPresentationController presentationTransitionWillBegin] ()
- __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke ()
- __56-[UIPresentationController runTransitionForCurrentState]_block_invoke ()
- _applyBlockToCFArrayCopiedToStack ()
- _afterCACommitHandler ()
- __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
- __CFRunLoopDoObservers ()
- __CFRunLoopRun ()
- CFRunLoopRunSpecific ()
- GSEventRunModal ()
- UIApplicationMain ()
I've tried several variations of code ordering & using a sourceView & sourceRect instead of barButtonItem for the popover anchor, but none of them help.
Thanks.