2013-10-08 117 views
2

我有一个带动态原型的UITableView。 我实现了下面的代码,所以当我选择一行时,它将被标记,并且之前选择的行将被标记。 但是,例如,我选择的行显示在屏幕的中间,然后当我向上或向下滚动时,另一个单元(位于屏幕的相同中间位置)被标记。总之,每个视图都有一个选中的单元格。 请指教。当你向上或向下滚动时,选择一个UITableViewCell选择在同一位置的其他单元格

- (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; 
} 
+0

显示您的代码cellForRowAtIndexPath –

回答

0

也许你在你的cellForRowAtIndexPath方法会覆盖accessoryType - 这被称为每次表将要绘制它是看不见之前新行(像你描述的,当你向上/向下滚动)。

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

0

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

相关问题