我想要记住UICollectionView中一个项目的索引(indexPath.item),在稍后的时间,当视图被替换并恢复后,滚动到已经记住的项目。
在记住项目时,indexPath和indexPath.item如下:
indexPath is: <NSIndexPath 0x1d87b380> 2 indexes [0, 32]
indexPath.item is: 32
当稍后重新计算该项的indexPath时,indexPath和indexPath.item是:
indexPath is: <NSIndexPath 0x1d8877b0> 2 indexes [0, 32]
item is: 32
我尝试使用以下方法滚动到记忆位置:
NSIndexPath *iPath = [NSIndexPath indexPathForItem:i inSection:0];
[self collectionView scrollToItemAtIndexPath:iPath atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
我收到了一个错误消息:
attempt to scroll to invalid index path
[section, row]
这样的形式,请尝试使用NSLog
打印[self.collectionView numberOfItemsInSection:section];
并告诉我们。 - micantox