我正在尝试滚动到 UICollectionView
中的指定索引路径:
if ([self collectionView:self.collectionView numberOfItemsInSection:0] > self.activeIndexPath.row && self.activeIndexPath.row > 0)
[self.collectionView scrollToItemAtIndexPath:self.activeIndexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
但是我总是因为这个错误而崩溃:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'attempt to scroll to invalid index path: <NSIndexPath: 0x1ff80a30> {length = 2, path = 0 - 40}
如何在滚动前验证索引路径?我的收藏 View 只有 1 个部分。
最佳答案
检查并验证您传递的 indexPath。
如果没问题,请尝试记录 collectionView 的 numberofItemsInSection。
然后,在滚动到 indexPath 之前尝试重新加载您的 collectionView,例如:
[self.collectionView reloadData];
关于ios - 检查 `UICollectionView` 索引路径是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38781619/