I have an Horizontal
UICollectionView
on my app and I want to load more data when the user reaches the end (or nearly to the end) of UICollectionView w
You may use cellForItem or willDisplayItem methods of collection view. Check if the last cell is being displayed, and load your data. For example:
Swift:
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if (indexPath.row == dataSource.count - 1 ) { //it's your last cell
//Load more data & reload your collection view
}
}
Objective-C:
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == dataSource.count - 1 ) { //it's your last cell
//Load more data & reload your collection view
}
}