UIPopoverPresentationController不调用UIAdaptivePresentationControllerDelegate方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UIPopoverPresentationController不调用UIAdaptivePresentationControllerDelegate方法相关的知识,希望对你有一定的参考价值。

我试图通过UIPopoverPresentationController在iPad上呈现popover。一切都很好,但似乎没有UIAdaptivePresentationControllerDelegate的方法被称为。

AddRewardController *addRewardVC = [[AddRewardController alloc] initWithNibName:@"AddRewardController" bundle:nil];
addRewardVC.modalPresentationStyle = UIModalPresentationPopover;
addRewardVC.preferredContentSize = CGSizeMake(500, 255);

UIPopoverPresentationController *popVC = addRewardVC.popoverPresentationController;
popVC.delegate = self;
popVC.sourceView = self.view;;
popVC.sourceRect = CGRectMake(self.view.center.x, self.view.center.y, 1.0f, 1.0f); // present in center of view
popVC.permittedArrowDirections = 0; //I dont want to show arrow so i set it to 0

[self presentViewController:addRewardVC animated:YES completion:nil];

我的视图控制器同时实现UIAdaptivePresentationControllerDelegateUIPopoverPresentationControllerDelegate

我像这样实现UIAdaptivePresentationControllerDelegate委托(但没有一个被调用)

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationFullScreen;
}

- (UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style {
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller.presentedViewController];
    return navController;
}

我做错了什么,为什么不调用我的委托方法?

答案

使用此委托方法: -

(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection;

您实施的方法仅适用于iPhone。

以上是关于UIPopoverPresentationController不调用UIAdaptivePresentationControllerDelegate方法的主要内容,如果未能解决你的问题,请参考以下文章