Saturday, 5 February 2011

To toggle the "Tick" in a UITableViewCell

To check or uncheck a "tick" box in a UITableViewCell cell and also unhighlight it afterwards.

First make sure it's accessoryType is set:

cell.accessoryType = UITableViewCellAccessoryCheckmark;

And then in the didSelectRowAtIndexPath method:


// Toggle the "Tick" on and off
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
}else if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
// This removes the highlighting of the Cell
[tableView deselectRowAtIndexPath:indexPath animated:YES];

No comments:

Post a Comment