Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ios 6, how do you use pass data between View controller holding 'Container View' object and Table View controller that is embedded in it?

I have a view controller with a label and textfield. I also added a container view which points to another table view controller with one section and 3 rows, basically static table view. I am unable to find any documentation / example which tells you how you pass data between View controller holding the Container View and Table View container embedded in the container view. I want both sided communication ?

like image 286
Vidya Bansal Avatar asked Feb 02 '13 01:02

Vidya Bansal


2 Answers

The controller embedded in the container view (in storyboard), is automatically added as a childViewController of the controller in which the container view is added. Just to make sense of what I mean, add this line, in your viewDidLoad method of the base controller :

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

So lets say in VC1, you add a container view with an embedded controller VC2 (your tableViewController), then the above statement will log VC2 as a child of VC1. To access VC2 from VC1, you just use [self.childViewControllers objectAtIndex:0], and to access VC1 from VC2, just use self.parentViewController.

Hope this helps

like image 144
Dhruv Goel Avatar answered Nov 15 '22 10:11

Dhruv Goel


If you set things up in a storyboard, you use segues. Just like most everything else in storyboards.

See Access Container View Controller from Parent iOS

like image 24
Jeffery Thomas Avatar answered Nov 15 '22 08:11

Jeffery Thomas