iOS NSDictionary pass through function -
i have view controller named secondviewcontroller , when user selects article wants read, want navigate thirdviewcontroller , pass nsdictionary article data.
- (void) touchbuttonblock:(nsinteger) select { nslog(@"touchbuttonblock"); nsdictionary *dict; switch (select) { case 0: { nsmutabledictionary *tmpdict = [[nsmutabledictionary alloc] init]; nsmutabledictionary *val = [[nsmutabledictionary alloc] init]; [val setobject:@"article360.html" forkey:@"page"]; [val setobject:@"img.png" forkey:@"img"]; [val setobject:@"art1" forkey:@"name"]; [tmpdict setobject:val forkey:[nsnumber numberwithint:0]]; val = [[nsmutabledictionary alloc] init]; [val setobject:@"article360.html" forkey:@"page"]; [val setobject:@"img.png" forkey:@"img"]; [val setobject:@"art2" forkey:@"name"]; [tmpdict setobject:val forkey:[nsnumber numberwithint:1]]; dict = [nsdictionary dictionarywithdictionary:tmpdict]; //[tmpdict release]; //[val release]; break; } nsdictionary *immdict = [nsdictionary dictionarywithdictionary:dict]; articleselectlistviewcontroller *selectorview = [[articleselectlistviewcontroller alloc] initwitharticlesdata:immdict]; [self.navigationcontroller pushviewcontroller:selectorview animated:yes]; [selectorview release]; }
here assing nsdicitionary:
- (id)initwitharticlesdata:(nsdictionary *)data { self = [super initwithnibname:nil bundle:nil]; if (self) { articles = data; ... }
but in other functions being called after user interaction articles variable seems incorrect - doesn't contain data.
where make mistake ?
make copy of dictionary , assign it.
- (id)initwitharticlesdata:(nsdictionary *)data { self = [super initwithnibname:nil bundle:nil]; if (self) { articles = [data copy]; ... }
Comments
Post a Comment