如何从其他 UIViewController 中的 containerView 访问 UIViewController?

How get access from UIViewController, which is a containerView in other UIViewController?

我有两个 UIViewController。 SecondViewController 是 FirstViewController 中的一个 ContainerView。

我知道如何从 First 访问到 Second,但不知道如何执行相反的操作(Second to First)。 也许有人知道我该怎么做。

感谢所有的回答和想法!

如果 SecondViewController 被正确设置为包含(即子)视图控制器,那么它的 parent 属性 将指向 FirstViewController.

您可以使用父视图控制器访问视图控制器属性。

   if let vc = parent as? FirstViewController {
        }

您可以将 FirstViewController 设置为 SecondViewController

的代表