向上或向下滚动时select一个UITableViewCellselect在同一位置的其他单元格

我有一个UITableView与dynamic原型。 我实现了下面的代码,所以当我select一行时,它将被标记,并且之前select的行将被取消标记。 但是,例如,我select的行显示在屏幕的中间,然后当我向上或向下滚动时,另一个单元(位于屏幕的相同中间位置)被标记。 总之,每一个观点,中间都有一个选定的细胞。 请指教。

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSIndexPath *oldIndexPath = [self.tableView indexPathForSelectedRow]; [self.tableView cellForRowAtIndexPath:oldIndexPath].accessoryType = UITableViewCellAccessoryNone; [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; return indexPath; } 

或许你正在覆盖你的cellForRowAtIndexPath方法中的accessoryType – 每当表格即将绘制新的行时,就会调用这个新的行(这在你向上/向下滚动时描述过)。

您还需要在该函数中处理它,并更新accessoryType,否则将随机重用具有不同accessoryType的单元格。

您正在修改单元格的视觉效果,而不是更新数据模型。 将选定的索引path存储在@property某处,并调整cellForRowAtIndexPath accessoryType