获取对容器视图的视图控制器的引用

获取对容器视图的视图控制器的引用

问题描述:

我有一个viewController,它包含一个ContainerView(正在设置一个ViewController)。我正在设置一个segue和prepareforsegue方法,我想获得一个嵌入在容器View中的viewController的引用。我怎么做。我知道使用segue.destinationViewController我们可以获得对UIViewController的引用,但我还想设置ContainerView指向的viewController。

I have a viewController which contains a ContainerView(which is setting up a ViewController). I am setting up a segue and in prepareforsegue method I want to get a reference to a viewController which is embedded in the container View. How do I do that. I know that using segue.destinationViewController we can get a reference to UIViewController but I want to also setup the viewController that is being pointed to by the ContainerView.

你已经有了答案。容器视图是视图,而不是视图控制器。它只定义了嵌入segue将子视图控制器的内容视图放入的框架。

You have your answer already. The container view is a view, not a view controller. It just defines the frame into which the embed segue will put the child view controller's content view.

当系统创建子VC时,它将调用prepareForSegue方法,并且此时,segue.destinationViewController将包含容器视图中包含的子视图控制器。

When the system creates the child VC, it will call your prepareForSegue method, and at that point, segue.destinationViewController will contain the child view controller that is contained in the container view.