UIPopoverPresentationController不调用UIAdaptivePresentationControllerDelegate方法

时间:2015-10-30 08:49:16

标签: ios ipad ios8 delegates popover

我试图通过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;
}

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

1 个答案:

答案 0 :(得分:2)

使用此委托方法: -

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

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