ios - Conflict between a tableView index and NSArray objectAtIndex -


i'm implementing tableview (class listeexercice), showing list of customized cells. these cells defined in class (class exercicetablecell).

in class listeexercice, create nsarray follow in viewdidload method:

table1 = [nsarray arraywithobjects:@"exo1", @"exo2", nil]; table2 = [nsarray arraywithobjects:@"10:00", @"10:00", nil]; 

then in same class, in order display cells in table

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection(nsinteger)section - (nsarray *)sectionindextitlesfortableview:(uitableview *)tableview 

the problem got happens ins following method, code in order display right cell located :

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {  static nsstring *exercicetableidentifier = @"exercicetablecell"; exercicetablecell *cell = (exercicetablecell *)[tableview dequeuereusablecellwithidentifier:exercicetableidentifier]; if (cell == nil)  {     nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"exercicetablecell" owner:self options:nil];     cell = [nib objectatindex:0]; }   //label1 label cell defined in exercicetablecell class.  cell.label1.text = [tableintituleexercice objectatindex:indexpath.row];  return cell; 

}

the problem got conflict between these 2 lines:

cell = [nib objectatindex:0]; 

and

cell.label1.text = [table1 objectatindex:indexpath.row]; 

apparently there conflict between 2 "objectatindex". not have warning, app crash, , thread saying "thread 1 : exc_bad_access (code = 1 ....)

any advice on do?

if you're not using arc, it's plain memory management error. have retain 2 arrays in these lines:

table1 = [nsarray arraywithobjects:@"exo1", @"exo2", nil]; table2 = [nsarray arraywithobjects:@"10:00", @"10:00", nil]; 

otherwise, objects have been released before tableview:cellforrowatindexpath: being called. it's errors these should use property setters assign values ivars/properties. setters care proper memory management you.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -