【发布时间】:2019-10-04 17:16:37
【问题描述】:
我有片刻的困惑,我无法解决一件非常简单的事情。
我的 CollectionView 有 50 个单元格,我想使用“下一步”按钮和“返回”按钮在单元格之间来回滚动。我知道 scrollToItemAtIndexPath 方法,但我无法找到正确的 IndexPath .. 有人可以帮助我吗?
这是我的代码:
// My personal method
-(void)scrollYearAtIndex:(NSInteger)index {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:0];
[_collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
}
// Show Next Items
-(void)didScrollNextYear {
[self scrollYearAtIndex:????];
}
// Show Previous Items
-(void)didScrollPreviousYear {
[self scrollYearAtIndex:????];
}
【问题讨论】:
-
你的下一个/上一个逻辑是否可以在当前可见的单元格或当前选定的单元格上工作?
-
所有可见单元格:)
标签: ios objective-c uicollectionview uibutton nsindexpath