Question

I have 2 view controllers connected by using segue.How can i pass one dictionary {"fist":1,"second":2} in the secondviewcontroller to first viewcontroller.

Was it helpful?

Solution

You have to add identifier to your segue in storyboard. In yout source view controller override prepareForSegue: method:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"YOURIDENTIFIER"]) { //<-YOURIDENTIFIER the same as you set up in storyboard

        UIViewController *vc = (UIViewController*)segue.destinationViewController;
        // You should cast destination view controller to your custom view controller sub class:
       //YourViewController *vc = (YourViewController*)segue.destinationViewController;
       // Pass the data
       vc.myDictionary = @{{"fist":1,"second":2};
       // I assume you have property myDictionary in YourViewController class
    }
}

Hope this help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top