0

The title says it, and I think it's pretty much a no-brainer but I can't find the answer. I think the code describes what I try to do.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSLog(@"Selected Row");
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
static NSString *CellIdentifier = @"accountCell";
UITableViewCell *allCells = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
allCells.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

So - first should all cells have no checkmarks, then I wanna add a checkmark to the selected one.

Rhyder
  • 101
  • 2
  • 14
  • I am not on my work computer but how about reloading all table data in willSelectRowAtIndexPath and then giving accessory to the cell which will be selected? – Yunus Nedim Mehel Oct 28 '13 at 21:56

2 Answers2

1

Every time the didSelectRowAtIndexPath method is called, go through a for loop that resets all the cells to their original accessory type. Then update the cell with the selected index path with a check mark like so:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    for (UITableViewCell *cell in[self.tableView visibleCells]) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;

}
Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81
0

See here for a possible solution. You don't need to iterate over all cells

Community
  • 1
  • 1
Sal
  • 1,230
  • 13
  • 21