indexPath和indexPath.row(iphone)之间的区别

时间:2011-08-20 14:24:31

标签: objective-c nsindexpath

我对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];
            }
        }
    }
}

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

非常感谢

1 个答案:

答案 0 :(得分:4)

NSIndexPath类的每个实例都有两个属性:row和section(Documentation
tableView的每个单元对应于唯一的indexPath(第M个部分中的第N行)。通常只有一个部分,人们只使用row来引用数据。

相关问题