indexPath 和indexPath.row 之间的区别(iphone)
我对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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.