Search code examples
iosobjective-cnsmutabledictionary

How to pass NSMutableDictionary from one viewController to another View controller?


firstviewcontroller.m

@property (nonatomic) NSMutableDictionary *json;

.h
@synthesis json;

    viewdidload()

    {
        nslog(@"%@",json);
    }

secondviewcontroller.h

firstviewcontroller *FVC = [[firstviewcontroller alloc]init];

FVC.json = @"My NSMutableDictionary"

This is my code, in firstviewcontrol NSMutableDictionary value is null. How to solve this?


Solution

  • Use below code to load your xib file using [NSBundle mainBundle] approach and the first object in returned array is your controller. Then assign your dictionary object and then push using navigationcontroller.

        NSArray * array = [[NSBundle mainBundle] loadNibNamed:@"<your xib file name without .xib extension>" owner:self options:nil];
    secondViewConroller *cntrl = [array objectAtIndex:0];
    cntrl.json = <your dictionary data>;
    [self.navigationController pushViewController:cntrl animated:YES];