2

我对 indexPath 和 indexPath.row 感到困惑,tableView 的每个单元格是否对应一个 indexPath?那么我们为什么要寻找这个 indexPath 的“行”呢?我检查了文档,但我认为它让我感到困惑。

我找到了这段代码:

// this method is used in case the user scrolled into a set of cells that don't have their app icons yet
- (void)loadImagesForOnscreenRows
{
    if ([self.entries count] > 0)
    {
        NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];
        for (NSIndexPath *indexPath in visiblePaths)
        {
            AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];

            if (!appRecord.appIcon) // avoid the app icon download if the app already has an icon
            {
                [self startIconDownload:appRecord forIndexPath:indexPath];
            }
        }
    }
}

你能解释一下两者之间的区别吗?

非常感谢

保罗

4

1 回答 1

4

NSIndexPath 类的每个实例都有两个属性:行和节(文档
tableView 的每个单元格对应于唯一的 indexPath(第 M 节中的第 N 行)。通常只有一个部分,人们仅row用于参考数据。

于 2011-08-20T14:56:43.173 回答