我试图将数据传递给viewController。问题在于它嵌入在navigationController中,并且以模态显示。我如何传递到以模态呈现并嵌入在导航控制器中的viewController

func offerNew(sender: UIBarButtonItem) {


    let offerVC = self.storyboard?.instantiateViewControllerWithIdentifier("OfferViewController") as UINavigationController


    self.presentViewController(offerVC, animated: true, completion: nil);
}


我试过了

    let offerVC = self.storyboard?.instantiateViewControllerWithIdentifier("offerNavigation") as UINavigationController
    let targetVC = offerVC.topViewController as OfferViewController
    self.presentViewController(targetVC, animated: true, completion: nil);

最佳答案

我假设offerVC是其中嵌入了“目标”视图控制器的navigationController。如果是这样,则可以通过offerVC的topViewController属性访问目标视图控制器。所以

let targetVC = offerVC.topViewController as TargetViewController


给您参考。然后,您可以访问目标视图控制器的属性。

编辑

但是您应该提供OfferVC-它会自动显示targetVC。

self.presentViewController(offerVC, animated: true, completion: nil);

08-19 11:53