Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 检查表视图单元格上的登录_Ios_Uitableview - Fatal编程技术网

Ios 检查表视图单元格上的登录

Ios 检查表视图单元格上的登录,ios,uitableview,Ios,Uitableview,当我使用此选项对所选单元格进行复选标记时,我的表视图中有100个单元格 [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; 它在其他单元格上也会自动显示,我不明白为什么会发生这种情况。如果重复使用表格视图单元格,则必须确保不仅在特定单元格上设置了复选标记,而且在其他单元格上也未设置复选标记 比如说 if (somethingHappens) { [ta

当我使用此选项对所选单元格进行复选标记时,我的表视图中有100个单元格

[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;

它在其他单元格上也会自动显示,我不明白为什么会发生这种情况。

如果重复使用表格视图单元格,则必须确保不仅在特定单元格上设置了复选标记,而且在其他单元格上也未设置复选标记

比如说

if (somethingHappens) {
   [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
} else {
   [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}

始终在显示前清除单元格,而不是检查条件。试试这个:

[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;

if (shouldCheckMark) {
   [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}