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

发布于 2024-11-30 11:20:31 字数 828 浏览 3 评论 0原文

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

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

非常感谢

保罗

i am confused about indexPath and indexPath.row, does each cell of a tableView correspond to an indexPath? so why do we look for the "row" of this indexPath? i checked the doc but i think it confuses me.

i found this code :

// 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];
            }
        }
    }
}

Can you explain me the difference between the two?

Thanks a lot

Paul

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒一口袋星星 2024-12-07 11:20:31

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

Each instances of NSIndexPath class has two properties: row and section (Documentation)
Each cell of tableView corresponds to unique indexPath (N-th row in M-th section). Often there is only one section and people use only row to reference to the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文