{"id":20544330,"url":"https://github.com/ratulsharker/tableviewpaginator","last_synced_at":"2025-09-08T07:36:04.194Z","repository":{"id":56923700,"uuid":"143600412","full_name":"ratulSharker/TableviewPaginator","owner":"ratulSharker","description":"UITableview Pagination, Made easy !!!","archived":false,"fork":false,"pushed_at":"2018-12-22T15:12:11.000Z","size":177,"stargazers_count":19,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T23:11:19.706Z","etag":null,"topics":["paginate","paginated-tables","pagination","paginator","uitableview","uitableviewcontroller","uitableviewdatasource","uitableviewdelegate","uiviewcontroller"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ratulSharker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-05T09:40:04.000Z","updated_at":"2024-05-21T05:23:26.000Z","dependencies_parsed_at":"2022-08-21T05:20:52.702Z","dependency_job_id":null,"html_url":"https://github.com/ratulSharker/TableviewPaginator","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratulSharker%2FTableviewPaginator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratulSharker%2FTableviewPaginator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratulSharker%2FTableviewPaginator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratulSharker%2FTableviewPaginator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ratulSharker","download_url":"https://codeload.github.com/ratulSharker/TableviewPaginator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860117,"owners_count":21173339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["paginate","paginated-tables","pagination","paginator","uitableview","uitableviewcontroller","uitableviewdatasource","uitableviewdelegate","uiviewcontroller"],"created_at":"2024-11-16T01:43:55.616Z","updated_at":"2025-04-14T09:52:58.075Z","avatar_url":"https://github.com/ratulSharker.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/ratulSharker/TableviewPaginator/blob/master/images/Banner.jpg?raw=true\"\u003e\u003c/img\u003e\n\n[![CI Status](https://travis-ci.org/ratulSharker/TableviewPaginator.svg?branch=master)](https://travis-ci.org/ratulSharker/TableviewPaginator)\n[![codebeat badge](https://codebeat.co/badges/e213907a-a6a3-4b9b-bca2-aad36067a9b7)](https://codebeat.co/projects/github-com-ratulsharker-tableviewpaginator-master)\n[![Version](https://img.shields.io/cocoapods/v/TableviewPaginator.svg?style=flat)](https://cocoapods.org/pods/TableviewPaginator)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-Compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/cocoapods/l/TableviewPaginator.svg?style=flat)](https://cocoapods.org/pods/TableviewPaginator)\n[![Platform](https://img.shields.io/cocoapods/p/TableviewPaginator.svg?style=flat)](https://cocoapods.org/pods/TableviewPaginator)\n[![Xcode](https://img.shields.io/badge/Xcode-10.1-blue.svg)](https://developer.apple.com/xcode)\n[![Swift](https://img.shields.io/badge/Swift-4.2-orange.svg)](https://swift.org)\n\n## \u003ca href=\"https://appetize.io/embed/7799zdgrhftqg8b2gpc73n4ct8?device=iphone6s\u0026scale=75\u0026orientation=portrait\u0026osVersion=11.4\"\u003eLive Demonstration\u003c/a\u003e\n\n## Example\n\nTo run the example project\n\n```ruby\npod try TableviewPaginator\n```\n\n## Installation\n\n\u003cdetails\u003e\n\u003csummary\u003eCocoaPods\u003c/summary\u003e\n\u003c/br\u003e\n\u003cp\u003eTableviewPaginator is available through \u003ca href=\"https://cocoapods.org\"\u003eCocoaPods\u003c/a\u003e. To install\nit, simply add the following line to your \u003ccode\u003ePodfile\u003c/code\u003e:\u003c/p\u003e\n\n\u003cpre\u003e\n\u003ccode class='ruby language-ruby'\u003epod 'TableviewPaginator' \u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eCarthage\u003c/summary\u003e\n\u003c/br\u003e\n\u003cp\u003eTableviewPaginator is available throguh \u003ca href=\"https://github.com/Carthage/Carthage\"\u003eCarthage\u003c/a\u003e, specify it in your \u003ccode\u003eCartfile\u003c/code\u003e:\u003c/p\u003e\n\n\u003cpre\u003e\u003ccode class=\"ogdl language-ogdl\"\u003egithub \"ratulSharker/TableviewPaginator\" ~\u0026gt; 0.3.3\n\u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eManually\u003c/summary\u003e\n\u003c/br\u003e\n\u003cp\u003eAdd the \u003ca href=\"https://github.com/ratulSharker/TableviewPaginator/blob/master/TableviewPaginator/Classes/TableviewPaginator.swift\"\u003eTableviewPaginator.swift\u003c/a\u003e file to your Xcode project and you are good to go.\u003c/p\u003e\n\u003c/details\u003e\n\n## Usage\n\n\u003cb\u003eStep 1:\u003c/b\u003e Import the `TableviewPaginator` module in swift.\n\n```swift\nimport TableviewPaginator\n```\n\n\u003cb\u003eStep 2:\u003c/b\u003e Take a reference to `TableviewPaginator` (say `tableviewPaginator`) into your controller. This example assumes that you use `UIViewController` as your controller.\n\n```swift\nprivate var tableviewPaginator: TableviewPaginator?\n```\n\n\u003cb\u003eStep 3:\u003c/b\u003e Initialize the `tableviewPaginator` in your `viewDidLoad` callback. Note that, before doing `initialSetup` method call, initialize your viewModel classes (from where you supply the data to view controller).\n\n```swift\noverride func viewDidLoad() {\n  // do all you model setup before initializing the tableviewPaginator\n  tableviewPaginator = TableviewPaginator.init(paginatorUI: self, delegate: self)\n  tableviewPaginator?.initialSetup()\n}\n```\n\n\u003cb\u003eStep 4:\u003c/b\u003e Now we have to implement two protocol `TableviewPaginatorUIProtocol` \u0026 `TableviewPaginatorProtocol`. `TableviewPaginatorUIProtocol` is responsible for specifying the `tableview` to working on and some other UI stuffs. `TableviewPaginatorProtocol` is responsible for let you know when to load and which data segment to load. The reason behind putting them inside of two different protocol is that, you may introduce a new class which is responsible for implementing `TableviewPaginatorUIProtocol` and keep the `TableviewPaginatorProtocol` implementation in your controller.\n\nImplementing `TableviewPaginatorUIProtocol`\n\n```swift\nextension YourViewController: TableviewPaginatorUIProtocol {\n    func getTableview(paginator: TableviewPaginator) -\u003e UITableView {\n        return yourTableview\n    }\n\n    func shouldAddRefreshControl(paginator: TableviewPaginator) -\u003e Bool {\n        return true\n    }\n\n    func getPaginatedLoadMoreCellHeight(paginator: TableviewPaginator) -\u003e CGFloat {\n        return 44\n    }\n\n    func getPaginatedLoadMoreCell(paginator: TableviewPaginator) -\u003e UITableViewCell {\n        if let cell = yourTableview.dequeueReusableCell(withIdentifier: \"YOUR_LOAD_MORE_CELL_IDENTIFIER\") as? YourLoadMoreCell {\n            // customize your load more cell\n            // i.e start animating the UIActivityIndicator inside of the cell\n            return cell\n        } else {\n            return UITableViewCell.init()\n        }\n    }\n\n    func getRefreshControlTintColor(paginator: TableviewPaginator) -\u003e UIColor {\n        return yourColorOfChoice\n    }\n}\n```\n\nImplementing `TableviewPaginatorProtocol`\n\n```swift\nextension YourViewController: TableviewPaginatorProtocol {\n    func loadPaginatedData(offset: Int, shouldAppend: Bool, paginator: TableviewPaginator) {\n        // call your data populating method here\n        // i.e given below\n        yourViewModel?.fetchData(offset: offset, limit: yourDataFetchLimit, shouldAppend: shouldAppend)\n    }\n}\n```\n\n\u003cb\u003eStep 5:\u003c/b\u003e Now you have to call some methods from `UITableViewDelegate`, `UITableViewDataSource` \u0026 your data fetched callbacks.\n\ninside of `heightForRowAt` call `heightForLoadMore` as following.\n\n```swift\noverride func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -\u003e CGFloat {\n    // if the current indexPath should show the Load more cell\n    // then heightForLoadMore will return a valid height\n    // height provided in the TableviewPaginatorUIProtocol\n    if let height = tableviewPaginator?.heightForLoadMore(cell: indexPath) {\n        return height\n    }\n\n    return yourCellHeight\n}\n```\n\ninside of `scrollViewDidScroll` will look like follwoing. `scrollViewDidScroll` is inherited from `UIScrollViewDelegate`.\n\n```swift\noverride func scrollViewDidScroll(_ scrollView: UIScrollView) {\n      tableviewPaginator?.scrollViewDidScroll(scrollView)\n  }\n```\n\ninside of `numberOfRowsInSection`, call `rowsIn` as following\n\n```swift\noverride func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -\u003e Int {\n    let yourCurrentNumberOfRows\n    let tableviewPagiantorLoadeMoreCells = (tableviewPaginator?.rowsIn(section: section) ?? 0)\n    return yourCurrentNumberOfRows + tableviewPagiantorLoadeMoreCells\n}\n```\n\ninside of `cellForRowAt`, call `cellForLoadMore` as following\n```swift\noverride func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -\u003e UITableViewCell {\n\n    if let cell = tableviewPaginator?.cellForLoadMore(at: indexPath) {\n        return cell\n    }\n\n    // write your own cell returning logic\n}\n```\n\nAll of this implementation was very straight forward. The last task is to, let `tableviewPaginator` know that you have successfully completed the data fetching. This requires a function call from your data fetch completion delegate / code block. Here i assume that, you provide a delegate by the `viewModel` \u0026 implement that delegate in your `viewController`. There must be a method saying that `dataFetched`. Implemetation will look like following\n\n```swift\nextension YourViewController: YourViewModelProtocol {\n    func dataFetched(success: Bool, dataCount: Int) {\n        if success {\n            tableviewPaginator?.incrementOffsetBy(delta: userCount)\n        }\n\n        tableviewPaginator?.partialDataFetchingDone()\n\n        yourTableView.reloadData()\n    }\n}\n```\nHere the `dataCount` parameter denoting the newly added number of data, more precisely newly added number of rows.\n\n## Tips\n1. `TableviewPaginator` is a pure swift class. If you intend to use multiple paginator in the single view controller (use case like, showing two different tableview in a single view controller, switching between them using the Segmented control) you may want to check against the passed `paginator` object for identifying which paginator is calling this delegate method. In that case user `===` **Identity Operators** to check for reference equality.\n2. Whenever you want to know that any data fetching is running or not use `YOUR_PAGINATOR.state.dataFetchingRunning`. This `Bool` will let you know that status. To check that all the data (all the pages) use `YOUT_PAGINATOR.state.allDataFetchingCompleted` this `Bool`. To know about the current offset use `state.offset`.\n\n## Author\n\nsharker.ratul.08@gmail.com\n\n## License\n\nTableviewPaginator is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratulsharker%2Ftableviewpaginator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fratulsharker%2Ftableviewpaginator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratulsharker%2Ftableviewpaginator/lists"}