How to Send data between view controllers StoryBoard Xcode

10,283

Use this method to pass the property in all of your view controllers

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"ShowNewVC"]) {
        NextViewController *nextVC = (NextViewController *)[segue destinationViewController];
        nextVC.someProperty = self.myProperty;
    }
}

Change the name of "NextViewController" to match yours. Be sure to add the "Segue Identifiers" in your Storyboard file.

This should work. However, when you have to pass this property trough so many view controllers, you can consider creating a Singleton "Data Manager" object to store the data. The View Controllers would have access to the data through the singleton.

Good luck!

Share:
10,283
user777304
Author by

user777304

Updated on June 05, 2022

Comments

  • user777304
    user777304 about 2 years

    Please help me..

    I want to pass data between different controllers in storyboard. For Example.

    First View Controller

    NSString *firstValue;
    
    firstValue = @"First Number";
    

    Now I want to send this to the result view controller and store in

    NSString *resultFromFirstVC;
    

    and show in label.

    [label setText: resultFromFirstVC];
    

    so the label show:

    First Number

    Xcode StoryBoard