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];
我的視圖控制器同時實現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;
}
難道我做錯了什麼,爲什麼它不叫我的委託方法?
對我來說問題是,通過「PerformSegue」調用PopoverViewController總是忽略代表。刪除故事板segue並手動組裝並通過presentViewController顯示解決了它。 – Alexandre