Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting reference to view controller of the container view [duplicate]

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.

like image 269
Roadblock Avatar asked Sep 07 '13 12:09

Roadblock


People also ask

How do I add a view controller container view?

Add a child view controller programmatically to your contentCall the addChildViewController: method of your container view controller to configure the containment relationship. Add the child's root view to your container's view hierarchy. Add constraints to set the size and position of the child's root view.

How do I find the view controller?

If you need to find the view controller that is responsible for a particular view, the easiest thing to do is walk the responder chain. This chain is built into all iOS apps, and lets you walk from one view up to its parent view, its grandparent view, and so on, until it reaches a view controller.


1 Answers

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.

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.

like image 124
Duncan C Avatar answered Oct 12 '22 23:10

Duncan C