ios - UITableViewCell that I didn't edit (portion that is not visible) become also edited. -
when set check mark on uitableviewcell, cell didn't set checkmark (that not visible) become checked. think when tableview reuses cell, wrong. how prepare it?
- (void)viewdidload { mytableview = [[uitableview alloc]initwithframe:cgrectmake(0, 100, 200, 300)]; [mytableview registerclass:[areacellinshakevc class] forcellreuseidentifier:@"areacell"]; mytableview.delegate = self; mytableview.datasource = self; mytableview.allowsmultipleselection = yes; [self.view addsubview:mytableview]; - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring* cellidentifier = @"cell"; customcell* cell = (customcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[customcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } homecoming cell; } - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { customcell* cell = (customcell *)[tableview cellforrowatindexpath:indexpath]; cell.accessorytype = uitableviewcellaccessorycheckmark; }
you need have logic in cellforforindexpath sets checkmark accordingly. means need store status of cell somewhere can check if ticked or not. so, set array, entry per row, check using indexpath.row value see if should checked or not. illustration in cellforrowatindexpath have this
if ([[selectedrow objectatindex:indexpath.row] isequaltostring:@"y"]) { cell.accessorytype = uitableviewcellaccessorycheckmark; } else { cell.accessorytype = uitableviewcellaccessorynone; }
in didselectrowatindexpath can set check accordingly by
if ([[selectedrow objectatindex:indexpath.row] isequaltostring:@"y"]) { [selectedrow replaceobjectatindex:indexpath.row withobject:@"n"]; } else { [selectedrow replaceobjectatindex:indexpath.row withobject:@"y"]; }
then reloaddata on tableview update checkmarks. hope helps.
ios objective-c uitableview
No comments:
Post a Comment