1

I have 100 cells in my table view, when I put check sign on selected cell using this

[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;

it's also visible on other cells automatically, I do not understand why this is happening.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jay
  • 11
  • 1

2 Answers2

1

Table view cells are reused, you have to make sure that not only the check mark is set on particular cells but also the check mark is not set on the others.

For example

if (somethingHappens) {
   [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
} else {
   [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
vadian
  • 274,689
  • 30
  • 353
  • 361
0

Always clear cell before show, than check condition. Try this:

[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;

if (shouldCheckMark) {
   [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
Nex
  • 71
  • 2