Reputation: 3301
Please check the below code..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// I may use this object to maintain check state.
ab_user_info *obj = nil;
obj = [self.listData objectAtIndex: [indexPath row]];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[contact_table reloadData];
}
As per the above code, I have checked all the table I am clicking, What should I do to uncheck again, I know I should change accessory type to None, but when, how do I know previously it was checked? Is there any API which tell us the accessary type of cell.
I have done in other table view by adding an extra member in my modal obj to track the checked and unchecked cell, however I just want to know is there any way without that?
Upvotes: 0
Views: 605
Reputation: 1752
Try below code :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// I may use this object to maintain check state.
ab_user_info *obj = nil;
obj = [self.listData objectAtIndex: [indexPath row]];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
}else{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
Upvotes: 1
Reputation: 4750
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark)
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
Upvotes: 3
Reputation: 3815
tableView is a Data Presenter view object
TableView is just used to 'display' data, it is not the manager or tracker of data. You need to track the attributes of data in the backend. I mean if you want to keep track of which all rows are checked or unchecked, it cannot be managed by TableView, you need to take care of it either by using NSArray or any other object type.
Upvotes: 1