Access Container View Controller from Parent iOS Access Container View Controller from Parent iOS ios ios

Access Container View Controller from Parent iOS


Yes, you can use the segue to get access the child view controller (and its view and subviews). Give the segue an identifier (such as alertview_embed), using the Attributes inspector in Storyboard. Then have the parent view controller (the one housing the container view) implement a method like this:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{   NSString * segueName = segue.identifier;   if ([segueName isEqualToString: @"alertview_embed"]) {       AlertViewController * childViewController = (AlertViewController *) [segue destinationViewController];       AlertView * alertView = childViewController.view;       // do something with the AlertView's subviews here...   }}


You can do that simply with self.childViewControllers.lastObject (assuming you only have one child, otherwise use objectAtIndex:).


for Swift Programming

you can write like this

var containerViewController: ExampleViewController?override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {    // you can set this name in 'segue.embed' in storyboard    if segue.identifier == "checkinPopupIdentifierInStoryBoard" {        let connectContainerViewController = segue.destinationViewController as ExampleViewController        containerViewController = connectContainerViewController    }}