In ios 6, how do you use the pass data between the View controller holding the Container View object and the Table View controller built into it?

I have a view controller with a label and a text field. I also added a container view that points to another table view controller with one section and three rows, mostly a static table view. I cannot find the documentation / example that tells how you transfer data between the View controller containing the Container View container and the Table View container embedded in the container view. Do I need two-way communication?

+6
source share
4 answers

The controller that is embedded in the container view (in the storyboard) is automatically added as a child of the Controller Controller in which the container view is added. To understand what I mean, add this line to your viewDidLoad method of the base controller:

NSLog(@"children : %@", self.childViewControllers); 

So, let's say in VC1, you add a container view with a built-in VC2 controller (your tableViewController), then the above statement will write VC2 as a child of VC1. To access VC2 from VC1, you simply use [self.childViewControllers objectAtIndex: 0] , and to access VC1 from VC2 just use self.parentViewController.

Hope this helps

+8
source

If you set things in the storyboard, you use segues. Like everything else in the storyboard.

See Access container view controller from parent iOS

+1
source

The UIViewController -childViewControllers and -parentViewController have new properties. You can use them.

Alternatively, you can establish a relationship yourself. Get tired of holding cycles. Perhaps the parent owns the child, and the child has a weak reference to the parent.

0
source

[self.childViewControllers lastOject] or [self.childViewControllers objectAtIndex:index]; , depending on how many child VCs you have.

0
source

All Articles