Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
926 views
in Technique[技术] by (71.8m points)

ios - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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()
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...