Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
922 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...