0

我正在使用 UITableView 和自定义单元格。当我单击一个单元格时,它会转到后屏幕,并将 indexPath 保存在 NSIndexpath 中;当我再次导航到 tableView 时,我更改了先前选择的单元格的 backgroundColor,以便用户可以识别选择。

 if (!self.indexvalue<0) {

    [[self.CountryCodeTableView cellForRowAtIndexPath:self.indexvalue] setBackgroundColor:[UIColor blueColor]];


}

但是当单元被重用时,它会为许多单元获得相同的 indexPath。你能告诉我如何解决它。我将如何识别电池何时被重复使用。

太感谢了!

4

1 回答 1

0

在导航回上一个视图控制器时,您可以使用以下方法来识别之前选择的单元格 - indexPathForSelectedRow

所以你可以使用 -

if (!self.indexvalue<0) {
    NSIndexPath *selectedRowIndexPath = [self.CountryCodeTableView indexPathForSelectedRow];
    [[self.CountryCodeTableView cellForRowAtIndexPath: selectedRowIndexPath] setBackgroundColor:[UIColor blueColor]];
}
于 2014-07-03T07:38:46.780 回答