从 UIPOpOverPresentationController 获取数据值到 UIViewController?

Get data value from UIPopOverPresentationController to UIViewController?

我想从显示的弹出窗口中获取值。我四处搜索并得到了这个答案

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    YourViewController *controller =  popoverController.contentViewController;
    MyData *data = controller.yourData;
    //Do something with data
}

但是我用过UIPopOverPresentationController。那么我将如何从这些委托方法中获取值呢

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {

   // var controller = popoverPresentationController.


}

或者我应该创建委托以将数据传回主视图控制器吗?

看看UIPopoverPresentationController的文档,它继承自UIPresentationController

它具有属性 presentingViewControllerpresentedViewController。其中之一应该引用您要访问的控制器并传递数据 to/get 数据来自:

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
    let controller = popoverPresentationController.presentedViewController
    // Fetch data from the presented controller
}