Table View Pagination Stand Alone Module

Table View Pagination Stand Alone Module

Released 4 years ago , Last update 3 years ago

FLTableViewPagination is a module that encapsulates server request (or other data sources) for pagination, including infinite scrolling.

The FLTableViewPagination module handles everything with the pagination, including sending a new request when the user scrolls past 50% of the last results, showing loading indicator cell when collecting data and when it's finished shows an customizable "end of results" cell.

In addition the module has it's own error handling with a customizable way of performing retries. The default behavior is a button for retry, but could easily be modified to be a timer based retry.

For the advanced user there is a possibility to add a filter to the pagination results, which makes it possible to filter all results depending on a NSPredicate.

All cells used (data cell, end of results cell, loading cell and error recovery cell) are customizable from the Storyboard or Programmatically and this is shown in the demo that is delivered together with the project.

The project is delivered with two Demos, one for iPad and one for iPhone. The project works for iOS 5.0+ and uses ARC.

Pricing

14 day 14-day money-back guarantee

$19.99

Application License

  • Perpetual license

  • 3 applications

  • Can distribute binary products only

  • Commercial use

  • 1 month support

Data Source Setup

The DataSource should be setup like this:

Inherit from the FLPagingDataSource

Example:

@interface FLDemoAlbumPagingDataSource : FLPagingDataSource

There are a couple of methods that have to be implemented

Creation of the cell containing the data

- (UITableViewCell *)createDataCellForTableView:(UITableView *)tableView withData:(id)data forIndexPath:(NSIndexPath *)indexPath;

How to load data

- (void)loadDataForPage:(NSUInteger)page withCompletion:(FLGetPageCompletionBlock)completionBlock;

Heights for the different cells

- (CGFloat)heightForDataCellWithIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)heightForLoadingCellWithIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)heightForErrorRecoveryCellWithIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)heightForEndOfResultsCellWithIndexPath:(NSIndexPath *)indexPath;

The optional methods to override are for customization of the different cells; loading cell, end of results cell and error recovery cell.

- (UITableViewCell *)createLoadingCellForTableView:(UITableView *)tableView  forIndexPath:(NSIndexPath *)indexPath;
- (UITableViewCell *)createEndOfResultsCellForTableView:(UITableView *)tableView  forIndexPath:(NSIndexPath *)indexPath;
- (UITableViewCell *)createErrorRecoveryCellForTableView:(UITableView *)tableView  forIndexPath:(NSIndexPath *)indexPath;

UITableViewController - Connect the Data Source

In order to connect the data source to an actual table view one needs to do the following:

In the examples below I will use the demo data source called: FLDemoAlbumPagingDataSourceIPhone

Create a property to store the data source

@interface FLDemoAlbumIPhoneViewController ()
@property (nonatomic, strong) FLDemoAlbumPagingDataSourceIPhone *albumDataSource;
@end

Initialize the data source

- (void)viewDidLoad
{
 [super viewDidLoad];
        [self setAlbumDataSource:[[FLDemoAlbumPagingDataSourceIPhone alloc] init]];
}

Redirect the UITableView datasource methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.albumDataSource numberOfRows];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.albumDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.albumDataSource tableView:tableView heightForRowAtIndexpath:indexPath];
}

It is of course possible to have multiple data sources, one for each section. To do this, simply create an array of data sources (inherit from the FLPagingDataSource) and access them through objectAtIndexPath:section. And in the numberOfSections method (UITableView datasource method), return the count of the data source array.

Features

  • Standalone Module
  • Pagination Logic Encapsulated
  • Customizable Loading Cell
  • Customizable Error Recovery Cell
  • Customizable End of List Cell
  • Automatic Error Handling
  • Dynamic Algorithm for Prefetching of Pages
  • Possibility to Apply Result Filter
  • iPhone/iPad Demo
  • ARC, iOS 6.0+, iOS 7 Optimised

Data Source - Load data from the server

For pagination to work, the data source (server or whatever you like) needs to support pagination.

Following is an example of how a server requests could look like, through a "manager" class.

- (void)loadDataForPage:(NSUInteger)page withCompletion:(FLGetPageCompletionBlock)completionBlock
{
    [FLDemoAlbumManager getAllForPage:page completion:^(NSArray *array, BOOL hasMorePages, NSError *error)
    {
        completionBlock(array, hasMorePages, error);
    }];
}

Where the FLDemoAlbumManager performs a requests with the parameter: page, which is the next page number. The returned values are an array with the data received, a BOOL that says if theres more pages and an error, if something occurred.

The important thing with this overridden method is how you call the completion block, it has to be called with the new data (not anything old), a BOOL that says if there's more pages and an error (most of the times nil). That means that the "manager" class could be implemented as you like, as long as you can provide these three variables.

If you like the functionality but doesn't need the pagination it self, the hasMorePages can be defaulted to NO and you will have the loading cell, error recovery and end of results cell in a simple way.

2 licenses, starting from From » $19.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.


Or enter your name and Email
  • I Ilia 2 years ago
    I'll be glad to buy it, with an explanation on how to implement it with swift, Thanks
  • SW SANJAY WAZA License holderApplication License
    6 month support
    Purchased on Jul 26, 2013
    4 years ago
    Can I use this on a UICollectionView ?