温柔一点,我正在学习。
下面的代码实际上工作得很好,除了在我第一次点击一行(适本地放置了一个复选标记)之后,我必须点击一个单元格两次才能让它删除相同的复选标记。
同样,删除后,需要点击两次才能将复选标记放回去。
如何解决这个问题?
- (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;
}
}
最佳答案
确保allowsMultipleSelection
未设置为YES
。不使用此属性时设置的默认值为NO
。如果您在类中的任何位置使用此属性,请尝试将其设置为 NO
以检查它是否有效。这将导致需要点击 2 次才能选择一行。
self.tableView.allowsMultipleSelection = NO;
关于ios - UITableView 中需要多次点击才能显示复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12335728/