Jeffrey Campecino
Jeffrey Campecino

Reputation: 14

Xcode: How To Access The Instance Of A View Controller Presented Using Storyboard?

When presenting a UIViewController using a button on Xcode through code, you usually use

[self presentViewController:viewControllerInstance animated:YES completion:nil];

Normally, before presenting the viewControllerInstance, I can make changes to that instance like setting some of its properties. However, this time I am using storyboard, and I was wondering how I would access the instance of the view controller being presented if it's not being created in code? I'd like to be able to set some properties of that specific UIViewController?

Thank you in advanced!

Upvotes: 0

Views: 264

Answers (1)

tounaobun
tounaobun

Reputation: 14857

In your UIViewController, add this callback method in .m file:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"Segue_Identifier"]) {

        YourViewController *dest = segue.destinationViewController;

        //dest.yourProperty = ...; set your presenting view controller's properties
    }
}

Upvotes: 2

Related Questions