iphone - UITableViewCellAccessory Disappears When Scrolled Off Screen -


i have uitableview filled objects. in didselectrowatindexpath method have uitableviewcellaccessorycheckmark appear when row selected , disappear when unselected.

heres code didselectrowatindexpath method:

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [tableview deselectrowatindexpath:indexpath animated:no];  uitableviewcell *curcell = [beertable cellforrowatindexpath:indexpath];  if (curcell.accessorytype == uitableviewcellaccessorycheckmark) {     [curcell setaccessorytype:uitableviewcellaccessorynone];     comparecount = (comparecount - 1);      if (tableview == [[self searchdisplaycontroller] searchresultstableview]) {         nsstring *objbeer = [searchresults objectatindex:indexpath.row];         [comparebeers removeobject:[searchresults objectatindex:indexpath.row]];         [comparecarbs removeobject:[carbamount objectatindex:[beernames indexofobject:objbeer]]];     }     else {         [comparebeers removeobject:[beernames objectatindex:indexpath.row]];         [comparecarbs removeobject:[carbamount objectatindex:indexpath.row]];     }  } else {     [curcell setaccessorytype:uitableviewcellaccessorycheckmark];     comparecount = (comparecount + 1);      if (tableview == [[self searchdisplaycontroller] searchresultstableview]) {         nsstring *objbeer = [searchresults objectatindex:indexpath.row];         [comparebeers addobject:[searchresults objectatindex:indexpath.row]];         [comparecarbs addobject:[carbamount objectatindex:[beernames indexofobject:objbeer]]];     }     else {         [comparebeers addobject:[beernames objectatindex:indexpath.row]];         [comparecarbs addobject:[carbamount objectatindex:indexpath.row]];     }  }  if (comparecount > 0) {     if (compareon == yes){     }     else {     comparebutton.enabled = yes;     uiimage *image = [uiimage imagenamed:@"redbutton.png"];     [comparebutton setimage:image];     } }  else {     comparebutton.enabled = no;     [comparebutton setimage:nil];     [comparebutton setcustomview:nil]; }  } 

i have cellforindexpath:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {   static nsstring *cellidentifier = @"customcell";  customcell *cell = (customcell *) [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) {      nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"customcell" owner:self options:nil];      (id currentobject in toplevelobjects){         if ([currentobject iskindofclass:[uitableviewcell class]]){             cell =  (customcell *) currentobject;             break;         }     } }  // setting separate tables correctly....   return cell; } 

my problem when cell selected scrolled out of view checkmark associated value gone when view.

what should keep checkmark disappearing?

thanks

your cells re-used scroll through data (that's dequeuereusablecellwithidentifier does). cell got checkmark in didselectrowatindexpath gets recycled different row , no longer has connection checked row.

you need set/unset accessory view in cellforrowatindexpath when checked rows scroll view, checked appropriately.


Comments