How do I pass data from my ViewController to a Container View?

前端 未结 4 1221
失恋的感觉
失恋的感觉 2020-12-30 01:10

I have a storyboard set up in XCode and have a MainViewController. In the MainViewController I have added a ContainerView which naturally creates a Segue with another VIewCo

4条回答
  •  醉酒成梦
    2020-12-30 01:25

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        // Make sure your segue name in storyboard is the same as this line
        if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
        {
            // Get reference to the destination view controller
            YourViewController *vc = [segue destinationViewController];
    
            // Pass any objects to the view controller here, like...
            [vc setMyObjectHere:object];
        }
    }
    

    I should also mention that because you are using a Container view, prepareForSegue will be triggered when you'll present the ViewController that holds the Container.

提交回复
热议问题