Reputation: 155
I wanna know how to check some cells in a table view. Does somebody know how to do that? I want, when the user presses a cell then a checkmark will appear and if the user presses again it ill disappear agian. The user should be available to check more than 1 cell at a time ;)
Upvotes: 0
Views: 2768
Reputation: 11839
you can set accessoryType
property of UITableViewCell
to UITableViewCellAccessoryCheckmark
. You just need to keep a BOOL
variable that will let you allow to change between UITableViewCellAccessoryNone
and UITableViewCellAccessoryCheckmark
.
EDIT 1 -
Code for doing so-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *tableCell = [tableView cellForRowAtIndexPath:indexPath];
BOOL isSelected = (tableCell.accessoryType == UITableViewCellAccessoryCheckmark);
if (isSelected) {
tableCell.accessoryType = UITableViewCellAccessoryNone;
}
else {
tableCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
Upvotes: 1