Awesome
Folio
Flexible way to detect when you scroll to the end of a UITableView
.
What is Folio?
Sometimes it's valuable to detect when you scroll to the end of a UITableView
. One scenario is if your app is trying to implement pagination. Folio's job is to tell you when you have scrolled to the bottom of your UITableView
. Nothing more, nothing less.
Why use Folio?
- Lightweight - Folio is very small. 1 class with a handful lines of code. Check it out for yourself.
- Works with sectioned
UITableView
- Some scrolling detectors only work if your table has 1 section. Folio will tell you when you scroll to the end of yourUITableView
no matter how many sections you have. It tells you when you get to the end of the last section of your table. - Flexible - You don't need to change your existing implementation. You don't need to use a custom subclass of
UITableView
. Use whateverUITableView
instance you want! - Easy to implement - There are 2 steps. (1) set delegate and (2) one function call.
Installation
Folio is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Folio', '~> version-here'
Replace version-here
with: as this is the latest version at this time.
Getting started
- Create an instance of Folio and set a
delegate
on it:
import UIKit
import Folio
class ViewController: UIViewController {
fileprivate var folio: Folio!
override func viewDidLoad() {
super.viewDidLoad()
folio = Folio(tableView: tableView)
folio.delegate = self
...
}
}
- Implement the
FolioDelegate
:
extension ViewController: FolioDelegate {
func reachedBottom(in tableView: UITableView) {
// Reached bottom of UITableView.
//
// Note: This function is only called once until you call `tableView.reloadData()`.
}
}
- In your
UITableViewDelegate
, pass some info to Folio:
extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
folio.tableView(tableView, willDisplay: cell, forRowAt: indexPath)
}
}
Example app
This project comes with an iOS app you can run and view the source code to get an idea of a full implementation of pagination with Folio.
To run the example app, follow these instructions:
cd Example/
pod install
Then, open the Folio workspace in XCode.
Author
- Levi Bostian - GitHub, Twitter, Website/blog
Contribute
Folio is open for pull requests. Check out the list of issues for tasks planned out, if there are any. Check them out if you wish to contribute in that way.
Want to add features to Folio? Before you decide to take a bunch of time and add functionality to the library, please, create an issue stating what you wish to add. This might save you some time in case your purpose does not fit well in the use cases of Folio. Nothing is stopping you from making a fork of this library and making any changes you wish!
Where did the name come from?
After a quick search for synonyms of "paging", folio came up. Folio is defined as arranging sheets of paper in a certain order. Fun word that aligns well with what it's common use case -> paging.
Credits
Header photo by JJ Ying on Unsplash
License
Folio is available under the MIT license. See the LICENSE file for more info.