Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to container view controller

I have simple ViewController which have one container view with TableViewController. At ViewController I loading data from external API and one part of that data, I need to pass into TableViewController in container.

Is there any way how to do that? Thank you!

like image 427
Martin Pernica Avatar asked Mar 29 '13 14:03

Martin Pernica


1 Answers

The controllers contained in a container view can be accessed by self.childViewControllers from the parent controller. If you only have one, then it will be at self.childViewControllers[0].


Note: regarding RD's excellent technique explained in the comment below; here's a typical example, tested and working: this simply goes in the VC of the overall scene. Just click on the segue itself (ie, the small symbol in the middle of the connecting arrow) to set the text identifier.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([segue.identifier isEqualToString:@"containerLogin"])
        self.vcLogin = (LoginVC *)segue.destinationViewController;

    if ([segue.identifier isEqualToString:@"containerStartNew"])
        self.vcStartNew = (StartNewVC *)segue.destinationViewController;

    }

Here's just how to do it in Swift: (you have to be careful with the unwrappers)

override func prepareForSegue(segue:(UIStoryboardSegue!), sender:AnyObject!)
    {
    if (segue.identifier == "feedContainer")
        {
        feed = segue!.destinationViewController as! Feed
        feed.someFunction()
        }
    }
like image 168
rdelmar Avatar answered Oct 06 '22 12:10

rdelmar