我正在尝试在我的应用中实施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和iPad。使用通常的垂直演示文稿以模态方式调出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,但它们都没有帮助。
感谢。
答案 0 :(得分:0)
你必须使用以下代码..
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:activityViewController animated:YES completion:nil];
}
//if iPad
else {
// Change Rect to position Popover
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[popup presentPopoverFromRect:yourRectWhatever inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}