我试图通过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];
我的视图控制器实现了UIAdaptivePresentationControllerDelegate
和UIPopoverPresentationControllerDelegate
我像这样实现UIAdaptivePresentationControllerDelegate
委托(但没有一个被调用)
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationFullScreen;
}
- (UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller.presentedViewController];
return navController;
}
我做错了什么,为什么不调用我的委托方法?
答案 0 :(得分:2)
使用此委托方法: -
(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection;
您实施的方法仅适用于iPhone。