温柔点,我在学习。
下面的代码实际上工作正常,除了在我第一次点击一行(适当地放置一个复选标记)之后,我必须点击一个单元格两次才能让它删除相同的复选标记。
同样,删除它后,需要轻按两次才能将复选标记放回去。
我该如何解决?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
NSInteger selectedRow = indexPath.row;
if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
if (selectedRow == 0) dm = 1;
else if (selectedRow == 1) athero1 = 1;
else if (selectedRow == 2) athero2 = 1;
else if (selectedRow == 3) athero3 = 1;
else if (selectedRow == 4) familyHistory1 = 1;
else if (selectedRow == 5) familyHistory2 = 1;
}
else {
thisCell.accessoryType = UITableViewCellAccessoryNone;
if (selectedRow == 0) dm = 0;
else if (selectedRow == 1) athero1 = 0;
else if (selectedRow == 2) athero2 = 0;
else if (selectedRow == 3) athero3 = 0;
else if (selectedRow == 4) familyHistory1 = 0;
else if (selectedRow == 5) familyHistory2 = 0;
}
}