Latest 0.3.9
Homepage https://github.com/WANGjieJacques/KissPaginate
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform
codecov

KissPaginate Simplify your implementation of tableView paginate.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Inherit from PaginateViewController

class ViewController: PaginateViewController {

    @IBOutlet weak var noElementLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        refreshElements()
    }

    override var getElementsClosure: (page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: Error) -> Void) -> Void {
        return getElementList
    }

    func getElementList(page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: Error) -> Void) {
        let elements = (0...20).map { "page (page), element index" + String($0) }
        delay(2) {
            successHandler(elements, true)
        }
    }

    override func displayNoElementIfNeeded(noElement: Bool) {
        noElementLabel.isHidden = !noElement
    }
}

extension ViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return elements.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
        let element = getElement(String.self, at: (indexPath as NSIndexPath).row)
        cell.textLabel?.text = element
        if elements.count == (indexPath as NSIndexPath).row + 1 {
            loadNextPage()
        }
        return cell
    }
}

Inherit from PaginateView

if your ViewController already has a parent class, you can inherit from the protocal PaginateView

class PaginateView: UIViewController, PaginateView {

    var presenter: PaginatePresenter!
    var refreshControl: UIRefreshControl!
    var bottomRefresh: UIActivityIndicatorView!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var noElementLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        presenter = PaginatePresenter(paginatable: self)
        presenter.start()
        tableView.dataSource = self
        refreshElements()
    }

    var getElementsClosure: (page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: Error) -> Void) -> Void {
        return getElementList
    }

    func getElementList(page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: Error) -> Void) {
        let elements = (0...20).map { "page (page), element index" + String($0) }
        delay(2) {
            successHandler(elements, true)
        }
    }

    func displayNoElementIfNeeded(noElement: Bool) {
        noElementLabel.isHidden = !noElement
    }
}

extension PaginateView: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return elements.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
        let element = getElement(String.self, at: (indexPath as NSIndexPath).row)
        cell.textLabel?.text = element
        if elements.count == (indexPath as NSIndexPath).row + 1 {
            loadNextPage()
        }
        return cell
    }
}

Requirements

Installation

KissPaginate is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'KissPaginate'

Author

WANG Jie, [email protected]

License

KissPaginate is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "KissPaginate",
    "version": "0.3.9",
    "summary": "Simplify your implementation of tableView paginate.",
    "description": "```nclass ViewController: PaginateViewController {n    @IBOutlet weak var noElementLabel: UILabel!nn    override func viewDidLoad() {n        super.viewDidLoad()n        tableView.dataSource = selfn        refreshElements()n    }nn    override var getElementsClosure: (page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: Error) -> Void) -> Void {n        return getElementListn    }nn    func getElementList(page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: Error) -> Void) {n        let elements = (0...20).map { "page (page), element index" + String($0) }n        delay(2) {n            successHandler(elements: elements, hasMoreElements: true)n        }n    }nn    override func displayNoElementIfNeeded(noElement: Bool) {n        noElementLabel.hidden = !noElementn    }n}nnextension ViewController: UITableViewDataSource {n    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {n        return elements.countn    }nn    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {n        let cell = tableView.dequeueReusableCellWithIdentifier("Cell")!n        let element = getElement(String.self, at: indexPath.row)n        cell.textLabel?.text = elementn        if elements.count == indexPath.row + 1 {n            loadNextPage()n        }n        return celln    }n}n```",
    "homepage": "https://github.com/WANGjieJacques/KissPaginate",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "WANG Jie": "[email protected]"
    },
    "source": {
        "git": "https://github.com/WANGjieJacques/KissPaginate.git",
        "tag": "0.3.9"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "KissPaginate/Classes/**/*",
    "pushed_with_swift_version": "3.0.1"
}

Pin It on Pinterest

Share This