当我在加载后检查第一个单元格时——没有任何反应,我一遍又一遍地点击——没有任何反应。我可以检查其他单元格、第二个、第三个等,然后我才能检查第一个单元格。这是我的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = indexPath.row;
NSUInteger oldRow = lastIndexPath.row;
if (oldRow != row) {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
或者也许你可以建议其他方式来制作它(只检查表格 View 中的一个单元格),因为我发现只有包含大量代码且难以理解的模型。
最佳答案
因为一开始你的lastIndexPath
变量是nil
,所以lastIndexPath.row
会返回0。如果你点击第一行,那一行也是0,所以不会进入if
语句。将该语句替换为:if (!lastIndexPath || oldRow != row)
关于ios - 当我尝试只检查 tableview 中的一个单元格时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19929882/