Latest 1.0.0
Homepage https://github.com/Ilhasoft/ISOnDemandTableView
License MIT
Platforms ios 9.0
Authors

Load your TableView content dynamically as you scroll

ISOnDemandTableView allows you to load the TableView content in little chunks as you scroll down the list instead of loading everything at once. This is important if your list contains a lot of information.

ISOnDemandTableView

Usage

To quickly implement an "on demand" list, make your UITableView a subclass of ISOnDemandTableView:

ISOnDemandTableView

In your ViewController, implement the ISOnDemandTableViewDelegate protocol. You’re required to implement two method at least:

extension ViewController: ISOnDemandTableViewDelegate {
    func reuseIdentifierForCell(at indexPath: IndexPath) -> String {
        return "YourCellIdentifier"
    }

    func onContentLoadFinishedWithError(_ error: Error?) {
        if let error = error {
            print(error.localizedDescription)
        }
    }
}

Loading Content

In order to load content for the TableView, you must create your own class subclassing ISOnDemandTableViewInteractor:

class CustomTableViewInteractor: ISOnDemandTableViewInteractor {

    override init() {
        super.init(paginationCount: 20)
    }

    override func fetchObjects(forPage page: UInt, with handler: (([Any]?, Error?) -> Void)!) {
        var objectsList: [Any] = []
        // get the content of the list for the current page
        handler(objectsList, nil)
    }
}

The TableView will automatically call this method and reload the list when you scroll to the bottom of the list.

In your viewDidLoad method, assing your ViewController as the delegate of the tableView and assing the correct TableViewInteractor subclass:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.register(UINib(nibName: "YourCellNibName", bundle: nil), forCellReuseIdentifier: "YourCellIdentifier")
    tableView.onDemandTableViewDelegate = self
    tableView.interactor = CustomTableViewInteractor()
    tableView.loadContent() // this must be called the first time
}

Installation

CocoaPods

To install it using CocoaPods, add the following line the project’s Podfile:

pod 'ISOnDemandTableView', '1.0.0'

Using ISOnDemandTableView with Parse

You can create a simple interator that retrieves content from a PFQuery with a few lines of code:

import UIKit
import Parse
import ISOnDemandTableView

class ParseTableViewInteractor: ISOnDemandTableViewInteractor {

    private var query: PFQuery<PFObject>
    private let emptyObjectsList: [AnyObject] = []

    init(query: PFQuery<PFObject>, paginationCount: UInt) {
        self.query = query
        query.limit = Int(paginationCount)
        query.skip = 0
        super.init(paginationCount: paginationCount)
    }

    override func fetchObjects(forPage page: UInt, with handler: (([Any]?, Error?) -> Void)!) {
        self.query.skip = Int(self.currentPage * self.paginationCount)
        query.findObjectsInBackground { objects, error in
            handler(objects ?? self.emptyObjectsList, nil)
        }
    }
}

Latest podspec

{
    "name": "ISOnDemandTableView",
    "version": "1.0.0",
    "summary": "A standard implementation for on-demand content in tableView",
    "description": "ISOnDemandTableView is a standard implementation for on-demand content in tableView that allows you to download content as you scroll",
    "homepage": "https://github.com/Ilhasoft/ISOnDemandTableView",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Dielson Sales": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Ilhasoft/ISOnDemandTableView.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/dielsonsaless",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": [
        "ISOnDemandTableView/*.h",
        "ISOnDemandTableView/*.m"
    ]
}

Pin It on Pinterest

Share This