Reputation: 21
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {
[selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
} else {
[selectedCell setAccessoryType:UITableViewCellAccessoryNone];
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
Okay so this is weird.
What's going on: When there are over about 10 or so rows, everything gets all glitchy and if I select the first row, the 8th and 10th row are selected. If I deselect the 8th and 10th row, nothing happens. If I select the 8th and 10th row, they get selected but the 3rd and 5th row get selected.
This happens on AppCoda's tutorial project too: http://www.appcoda.com/how-to-handle-row-selection-in-uitableview/
Is this just XCode? If it is, this is a huge glitch.
Upvotes: 1
Views: 696
Reputation: 34839
In your implementation of cellForRowAtIndexPath
, you need to check whether the row is selected, and set the accessory view accordingly. Otherwise, the accessory view is simply whatever it was when the cell went into the reuse queue.
Upvotes: 2
Reputation: 2717
I believe you're forgetting to update the cell after you change the accessory type:
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
Upvotes: 0