2015-10-30 35 views
1

我试图通过UIPopoverPresentationController在iPad上呈现popover。一切都很好,但似乎没有UIAdaptivePresentationControllerDelegate的方法被称为。UIPopoverPresentationController不调用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; 
} 

难道我做错了什么,为什么它不叫我的委托方法?

+0

对我来说问题是,通过“PerformSegue”调用PopoverViewController总是忽略代表。删除故事板segue并手动组装并通过presentViewController显示解决了它。 – Alexandre

回答

0

使用该委托方法: -

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

你的iPhone只执行工作的方法。