I'm having a moment of confusion and I can't solve a very simple thing.
My CollectionView has 50 cells and I would like to scroll back and forth between the cells using a "Next" button and a "Back" button. I am aware of the scrollToItemAtIndexPath method but I have problems finding the right IndexPath .. Someone can help me ?
This is my Code:
// 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:????];
}
This will give you current selected index path. In
didScrollNextYearmethod, increment indexPath.row by one. And indidScrollPreviousYear, decrement indexPath.row by one.Sample code: