I suggest you use a UICollectionView instead of a UITableView . At the same time, to download paginated data from your server, you need to add a couple of lines of code: You need to add variables to your view controller in order to track your data:
@property (nonatomic, assign) BOOL isLoading; @property (assign, nonatomic) BOOL hasNextPage; @property (assign, nonatomic) int currentPage;
Depending on which implementation you use, there are various methods for the implementation in which we will check whether the data is loaded correctly or not.
UITableView
And in your implementation of UITableViewDelegate add:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UICollectionView
And in your implementation of UICollectionViewDelegate add:
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
}
Then to load the following page:
- (void)loadNextPage:(int)pageNumber { if (self.isLoading) return; self.isLoading = YES;
I also suggest that you check the scroll direction and add it as a condition to load the next page. This answer explains how to accomplish this.
jbouaziz
source share