如何将ViewContorller的出口值传递给它的子视图Swift

问题描述:

我在同一个ViewControllerA中有ViewControllerA和一个子视图。我想知道如何将ViewContorllerA的出口标签值传递给它的子视图。如何将ViewContorller的出口值传递给它的子视图Swift

+0

如果我这样做是正确,你可以通过创建一个[*代表*](https://*.com/questions/40501780/examples-of-delegates-in-swift-3/40503024做#40503024)到您的子视图并通过其方法传递所需的值。提到的答案中包含“例如”部分,这可能是做这种事情的一个很好的起点。 –

+0

感谢您的示例。我无法得到它。我在VC_A中有一个插座标签,它包含一个子视图。事情是,suBView想要知道VC_A标签值的值。 (这里的子视图也在VC_A中)。 –

请尝试使用此方法。我认为这会对你有用。在这里传递你的插座价值。

  let destVC = self.storyboard?.instantiateViewController(withIdentifier: "CategoryDescriptionViewController_id") as? CategoryDescriptionViewController 

      destVC?.aTitleText = "" 

      destVC?.aDescText = "" 

      destVC?.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height) 
      self.addChildViewController(destVC ?? UIViewController()) 
      self.view.addSubview((destVC?.view)!) 
      destVC?.didMove(toParentViewController: self) 
+0

感谢您的示例。我无法得到它。我在VC_A中有一个插座标签,它包含一个子视图。事情是,suBView想要知道VC_A标签值的值。 (这里的子视图也在VC_A中)。 –