UICollectionView了解可见单元格日志

时间:2014-04-22 16:58:30

标签: ios uicollectionview

我想知道如何理解[collectionview indexPathsForVisibleItems]的结果。我试图实现延迟加载,我有一个collectionView,其中包含3个图像,当viewController加载时,可见2行半。在我的cellForItemAtIndexPath:我这样记录:

NSArray *visible = [collectionView indexPathsForVisibleItems];
NSLog(@"%@", visible);
for (NSIndexPath *index in visible) {
    NSLog(@"%d", index.row);
}

输出结果为:

2014-04-22 19:51:35.832 Test App[55175:60b] (
)

2014-04-22 19:51:35.834 Test App[55175:60b] (
"<NSIndexPath: 0xaac4f30> {length = 2, path = 0 - 0}"
)
2014-04-22 19:51:35.834 Test App[55175:60b] 0

2014-04-22 19:51:35.835 Test App[55175:60b] (
"<NSIndexPath: 0xaac4f30> {length = 2, path = 0 - 0}",
"<NSIndexPath: 0xaac5030> {length = 2, path = 0 - 1}"
)
2014-04-22 19:51:35.835 Test App[55175:60b] 0
2014-04-22 19:51:35.835 Test App[55175:60b] 1

2014-04-22 19:51:35.836 Test App[55175:60b] (
"<NSIndexPath: 0xaac50c0> {length = 2, path = 0 - 2}",
"<NSIndexPath: 0xaac4f30> {length = 2, path = 0 - 0}",
"<NSIndexPath: 0xaac5030> {length = 2, path = 0 - 1}"
)
2014-04-22 19:51:35.836 Test App[55175:60b] 2
2014-04-22 19:51:35.837 Test App[55175:60b] 0
2014-04-22 19:51:35.837 Test App[55175:60b] 1

2014-04-22 19:51:35.838 Test App[55175:60b] (
"<NSIndexPath: 0xaac4f30> {length = 2, path = 0 - 0}",
"<NSIndexPath: 0xaac50c0> {length = 2, path = 0 - 2}",
"<NSIndexPath: 0xaac5030> {length = 2, path = 0 - 1}",
"<NSIndexPath: 0xaac5150> {length = 2, path = 0 - 3}"
)
2014-04-22 19:51:35.838 Test App[55175:60b] 0
2014-04-22 19:51:35.839 Test App[55175:60b] 2
2014-04-22 19:51:35.839 Test App[55175:60b] 1
2014-04-22 19:51:35.839 Test App[55175:60b] 3

等等。当我滚动时,值会发生变化。我如何理解这些价值观?他们是否指出屏幕上有哪些细胞?如果是这样,怎么样?行 - 细胞?我很困惑。我知道我会使用didEndDisplayingCell:取消NSOperation,但我应该检查哪个值?

1 个答案:

答案 0 :(得分:1)

"<NSIndexPath: 0xaac5150> {length = 2, path = 0 - 3}"

path =之后的第一个数字是0 - 它是部分的数量。第二个数字是3 - 它是行/单元格的数量。

"<NSIndexPath: 0xaac4f30> {length = 2, path = 0 - 0}",
"<NSIndexPath: 0xaac50c0> {length = 2, path = 0 - 2}",
"<NSIndexPath: 0xaac5030> {length = 2, path = 0 - 1}",
"<NSIndexPath: 0xaac5150> {length = 2, path = 0 - 3}"

上面的行告诉我们,目前第一部分的4个第一行/单元格是可见的。