Skip to content

Manticore-iOSInfiniteScroll provides infinite scrolling for UITableView and supports TastyPie pagnination coupled with RestKit.

License

Notifications You must be signed in to change notification settings

rhfung/manticore-iOSInfiniteScroll

Repository files navigation

Manticore iOS Infinite Scroll

Manticore-iOSInfiniteScroll provides infinite scrolling for UITableView and supports TastyPie pagination coupled with RestKit.

Installation

Install using CocoaPods to this repository. Include the following line in Podfile:

pod 'AFNetworking-TastyPie', :git => 'https://github.com/YetiHQ/AFNetworking-TastyPie'
pod 'manticore-iOSInfiniteScroll', :git => 'https://github.com/rhfung/manticore-iOSInfiniteScroll.git'

Usage

Setup

Include the following header in your project file:

#import <manticore-iOSInfiniteScroll/MCPagination.h>

After you set up RestKit's RKObjectManager, you'll need to run this command once, for example:

RKObjectManager* manager = [RKObjectManager managerWithBaseURL:url];

// ...

[MCPaginationHelper setupMapping:manager];

This call must be made before the first RestKit call to map the meta key returned from the TastyPie server endpoint.

Single object responses

When RestKit returns back a single object, you can extract the single object using:

... success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    id singleObject = [MCPaginationHelper firstObjectWithoutMetaBlock:mappingResult.array];

    // ...
}

Array object responses

Infinite Scroll in a UITableView

When RestKit returns back an array of objects, you can bind a table to an array for infinite scroll. Infinite scroll is provided by SVPullToRefresh CocoaPod.

... success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    MCPaginationHelper* arr = [MCPaginationHelper helperWithUsername:[AppModel sharedModel].user.username apikey:[AppModel sharedModel].apikey urlPrefix:API_PREFIX restKit:mappingResult andTableView:yourTableView infiniteScroll:YES];

    // ...
}

Data-Only Parsing

MCPaginationHelper can be used without a UITableView. A shorter function signature is used:

MCPaginationHelper* arr = [MCPaginationHelper helperWithUsername:[AppModel sharedModel].user.username apikey:[AppModel sharedModel].apikey urlPrefix:API_PREFIX restKit:mappingResult];
// ...
// invoke infinite scroll
[arr loadMoreData];

Object mapping can be performed without infinite scroll. The following method is called:

    [MCPaginationHelper helperWithRestKit:mappingResult]

Dummy Mapping

A dummy mapping can be called too:

    [MCPaginationHelper helper]

Copying MCPaginationHelper

You can reuse MCPaginationHelper for other table views. Here's how you would do that:

    MCPaginationHelper* otherData = [MCPaginationHelper ...];
    MCPaginationHelper* newData = [MCPaginationHelper helperWithPaginator:otherData andTableView:tableView infiniteScroll:YES];

Using MCPaginationHelper

MCPaginationHelper objects provide two properties, which match exactly with TastyPie:

  • objects: Objects returned and mapped by RestKit. Manticore Communication (manticom) is the preferred way to create these other mappings, or write RestKit mapping by hand.
  • meta: Pagination information provided by TastyPie. next is the URL of the next page's resources. total_count refers to the total number of available objects and can be used to stop infinite scroll.

Revisions

0.0.10 - aded a delegate to remove dependency on Manticore-iOSViewFactory (new behaviour), __weak and __strong for ARC

0.0.9 - add support for non-authenticated infinite scroll

0.0.8 - continued fixing of crashes from 0.0.6

0.0.7 - loadMoreData:(UITableView*) has been removed from the API. loadMoreData will automatically load from the tableView that was used to construct MCPaginationHelper. Addresses the bug reported in build 0.0.6.

0.0.6 - possible bug fix to a crash that happens when UITableView gets deallocated on infinite scroll. A local copy of UITableView is saved, and UI updates are made synchronously in the block.

0.0.5 - bug fix in helperWithPaginator:andTableView:infiniteScroll: to prevent crashes during infinite scroll

To Do

This project is a work in progress.

  • Decouple authentication from TastyPie apikey
  • Simplify the pagination function by saving username, apikey, and url prefix in a global object.

About

Manticore-iOSInfiniteScroll provides infinite scrolling for UITableView and supports TastyPie pagnination coupled with RestKit.

Resources

License

Stars

Watchers

Forks

Packages

No packages published