objective c - Initialize NSMutableArray -
im new in xcode 3 , need this
i developed apps using uitableview , xml showed content.
i had 3 .xib files rootviewcontroller , secondviewcontroller , mainview.
so problem is: when try executed didselectrow in rootviewcontroller , access nsmutablearray *array in secondviewcontroller , replace *array value new array value in rootviewcontroller before pushed animation.
the array value on secondviewcontroller changed first time when pushed button , select other row, secondviewcontroller array kept read previous array not change new one. try initialize no luck
this code on rootviewcontroller uitableview (didselectrow):
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { if(2ndcontroller == nil) 2ndcontroller = [[detailviewcontroller alloc] initwithnibname:@"secondviewcontroller" bundle:[nsbundle mainbundle]]; //declare xml nsmutable array record listrecord *record = [self.entries objectatindex:indexpath.row]; //access secondviewcontroller nsmutable *record 2ndcontroller.record = [[[nsmutablearray alloc] init] autorelease]; //inserting value firstview secondview before push 2ndcontroller.record = record; //push animation [self.navigationcontroller pushviewcontroller:2ndcontroller animated:yes]; }
this second view controller :
- (uitableviewcell *)tableview:(uitableview *)tv cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithframe:cgrectzero reuseidentifier:cellidentifier] autorelease]; } switch(indexpath.section) { case 0: [cell settext:record.name]; break; case 1: [cell settext:record.age]; break; case 2: [cell settext:record.summary]; break; } return cell; }
hope can me..
thanks in advance.....
few things,
you do,
2ndcontroller.record = [[[nsmutablearray alloc] init] autorelease];
and follow with
[cell settext:record.name];
clearly, record
property doesn't seem instance of nsmutablearray
think array initialization part incorrect do, , mentioned,
2ndcontroller.record = record;
but problem think retaining uitableviewcontroller
subclass. have tried reloading data?
[self.tableview reloaddata];
add in viewwillappear
method of detailviewcontroller
.
Comments
Post a Comment