Giter Club home page Giter Club logo

jttableviewcontroller's Introduction

JTTableViewController

CI Status Version License Platform

A ViewController for manage pagination and loaders for iOS.

Installation

With CocoaPods, add this line to your Podfile.

pod 'JTTableViewController', '~> 1.0'

Screenshots

Example

Usage

Basic usage

#import <UIKit/UIKit.h>

#import <JTTableViewController.h>

@interface ViewController : JTTableViewController

@end
#import "ViewController.h"

@implementation ViewController

// If you don't implement this method, UITableViewAutomaticDimension will return by default
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Automatically return the height of nextPageLoaderCell, by default use UITableViewAutomaticDimension
    JTTABLEVIEW_heightForRowAtIndexPath
    
    return 44.;
}

// Must be implemented
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Automatically return nextPageLoaderCell and call startFetchingNextResults if needed
    JTTABLEVIEW_cellForRowAtIndexPath
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    
    // Do whatever you want to use the data
    cell.textLabel.text = self.results[indexPath.row];
    
    return cell;
}

// Must be implemented
- (void)startFetchingResults
{
    [super startFetchingResults];
    
    [service retrieveDataWithOffset:0 success:^(NSArray *results, BOOL haveMoreData) {
        [self didFetchResults:results haveMoreData:haveMoreData];
    } failure:^{
        [self didFailedToFetchResults];
    }];
}

// Must be implemented
- (void)startFetchingNextResults
{
    [super startFetchingNextResults];
    
    [service retrieveDataWithOffset:self.results.count success:^(NSArray *results, BOOL haveMoreData) {
        [self didFetchNextResults:results haveMoreData:haveMoreData];
    } failure:^{
        [self didFailedToFetchResults];
    }];
}

@end

You have to bind the tableView with the controller, automatically it will set the delegate and the dataSource.

You have to implement startFetchingResults and startFetchingNextResults methods. They are used to load data (from your web service for example). These methods must call super.

startFetchingResults is used to retrieve new data (erase all previous data) whereas startFetchingNextResults is used for get more data (the pagination).

didFetchResults:haveMoreData: must be call when startFetchingResults have successfuly retrieve data.

didFetchNextResults:haveMoreData: must be call when startFetchingNextResults have successfuly retrieve data.

didFailedToFetchResults must be call if startFetchingResults or startFetchingNextResults have failed to retrieve data.

The data are stored in results. Just use self.results to access to them.

There are some properties you can customize:

  • nextPageLoaderCell is the loader use for the pagination, it's a UITableViewCell
  • noResultsView is the view display when the results get from your webservice are empty
  • noResultsLoadingView is the view display when there is no results and you start fetching new data, used for the first load
  • nextPageLoaderOffset is the number of cells require before the last cell for calling startFetchingNextResults, by default it's 3

You can also override some methods:

  • showNoResultsView
  • hideNoResultsView
  • showNoResultsLoadingView
  • hideNoResultsLoadingView
  • endRefreshing

Requirements

  • iOS 7 or higher
  • Automatic Reference Counting (ARC)

Author

License

JTTableViewController is released under the MIT license. See the LICENSE file for more info.

jttableviewcontroller's People

Contributors

jonathantribouharet avatar

Watchers

Carabineiro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.