I have 5 cells in my tableview. User can select a row which sets the cells’ accessory to check marked. They can select multiple rows.
I want to make sure one cell is always check marked. How can I do this? All rows are check marked by default.
Here is the code I use in didSelectRow
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
[self.tableView deselectRowAtIndexPath:iIndexPath animated:YES];
}
Implement
tableView:willDeselectRowAtIndexPath:. If there is only one element selected, returnnilto indicate that the table may not deselect it.