Created
August 13, 2018 21:10
-
-
Save ogiba/7d84466e1d11281e3b268241823c1b7d to your computer and use it in GitHub Desktop.
UITableView Endless Scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fetchingMore = false | |
| func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
| let offsetY = scrollView.contentOffset.y | |
| let contentHeight = scrollView.contentSize.height | |
| if offsetY > contentHeight - scrollView.frame.height * 4 { | |
| if !fetchingMore { | |
| beginBatchFetch() | |
| } | |
| } | |
| } | |
| func beginBatchFetch() { | |
| fetchingMore = true | |
| //Load more data from server | |
| DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: { | |
| //Mark that job is done | |
| self.fetchingMore = false | |
| self.tableView.reloadData() | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment