Skip to content

Instantly share code, notes, and snippets.

@ogiba
Created August 13, 2018 21:10
Show Gist options
  • Save ogiba/7d84466e1d11281e3b268241823c1b7d to your computer and use it in GitHub Desktop.
Save ogiba/7d84466e1d11281e3b268241823c1b7d to your computer and use it in GitHub Desktop.
UITableView Endless Scroll
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