Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From within a view controller in a container view, how do you access the view controller containing the container?

This is tricky to word but I have a view controller (vc1) that contains a container view (I'm using storyboards). Within that container view is a navigation controller and a root view controller (vc2).

From within the vc2 how can I get access to vc1?

Or, how do I pass vc1 to vc2? (baring in mind that I'm using storyboards).

like image 453
Mark Bridges Avatar asked Jan 21 '14 10:01

Mark Bridges


1 Answers

You can use the prepareForSeguemethod in Vc1 as an embed segue occurs when the ContainerViewController is made a child. you can pass self as an obj or store a reference to the child for later use.

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {     NSString * segueName = segue.identifier;     if ([segueName isEqualToString: @"embedseg"]) {         UINavigationController * navViewController = (UINavigationController *) [segue destinationViewController];         Vc2 *detail=[navViewController viewControllers][0];         Vc2.parentController=self;     } } 

Edit: minor code fix

like image 129
Bonnie Avatar answered Nov 06 '22 22:11

Bonnie