You'd think this would be easy. With this code, I can check multiple rows in a table but what I WANT is to only have one row checked at a time. If a user selects a different row, then I want the old row to simply AUTOMATICALLY uncheck. Don't know how to do that. Here's my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *theCell = [tableView cellForRowAtIndexPath:indexPath];
if (theCell.accessoryType == UITableViewCellAccessoryNone) {
theCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else if (theCell.accessoryType == UITableViewCellAccessoryCheckmark) {
theCell.accessoryType = UITableViewCellAccessoryNone;
}
}
Thanks for any help you can lend!
Try this:
Simplest way is to save the selected IndexPath and check it in cellForRowAtIndexPath.
attached is the code:
step 1: initialize selectedIndexPath selectedIndexPath = [[NSIndexPath alloc] init];
step 2: in cellForRowAtIndexPath
step 3 : In didSelectRowAtIndexPath
It should work work try this Njoy :)
Swift
version would be:Swift 3
update:In Swift 2.0 I used this:
My way is deselect other cells during selecting: