【问题标题】:Reusable Cell is repeating same indexPath for many cells可重复使用的单元格为许多单元格重复相同的 indexPath
【发布时间】:2014-07-03 07:12:23
【问题描述】:

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

 if (!self.indexvalue<0) {

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


}

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

非常感谢!

【问题讨论】:

    标签: uitableview ios7 reuseidentifier


    【解决方案1】:

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

    所以你可以使用 -

    if (!self.indexvalue<0) {
        NSIndexPath *selectedRowIndexPath = [self.CountryCodeTableView indexPathForSelectedRow];
        [[self.CountryCodeTableView cellForRowAtIndexPath: selectedRowIndexPath] setBackgroundColor:[UIColor blueColor]];
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-27
      • 2017-12-29
      • 2018-04-19
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      相关资源
      最近更新 更多