Simple way to add a Pagination in UITableView

Pagination Objective-C

When there is a web service that contains tons of data to fetch the waiting time would be huge which is not really user-friendly. That’s why we have pagination to split the response into pages.
This approach will show you how to work with pagination inside a UITableView using of its delegate methods.

 

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // Check scrolled percentage
    CGFloat yOffset = tableView.contentOffset.y;
    CGFloat height = tableView.contentSize.height - tableView.frame.size.height;
    CGFloat scrolledPercentage = yOffset / height;
    
    // Check if all the conditions are met to allow loading the next page
    if (scrolledPercentage > .6f){
    // This is the bottom of the table view, load more data here.
    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *