【发布时间】:2015-05-15 02:12:36
【问题描述】:
我正在尝试在我的应用中实现UIPopoverPresentationController 以显示tableViewController。当应用程序在 iPhone 上运行但在 iPad 上崩溃时,它可以正常工作。
问题的代码是:
- (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;
}
这在 iPhone 上工作得很好,并以通常的垂直演示模式调出 tableView。
但是,它在 iPad 上失败并显示以下堆栈跟踪:
- 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 ()
我尝试了几种代码排序变体,并使用 sourceView 和 sourceRect 而不是 barButtonItem 作为弹出框锚点,但它们都没有帮助。
谢谢。
【问题讨论】: