Skip to content

Instantly share code, notes, and snippets.

@JarvisTheAvenger
Last active February 26, 2019 12:45
Show Gist options
  • Save JarvisTheAvenger/b62eac206f4b23fa085c919f3406c80a to your computer and use it in GitHub Desktop.
Save JarvisTheAvenger/b62eac206f4b23fa085c919f3406c80a to your computer and use it in GitHub Desktop.
var isDataLoading = false
var orders = []
var startIndex = 0
var activityIndicator = UIActivityIndicatorView()
func loadMoreOrders() {
//Get order from server handle your UI accordingly.
}
private func isLoadingIndexPath(_ indexPath: IndexPath) -> Bool {
return indexPath.row == self.orders.count - 1
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
handleEndLessScroll(indexPath)
}
func handleEndLessScroll(_ indexPath : IndexPath) {
guard isLoadingIndexPath(indexPath) else {
return
}
if !isDataLoading {
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
activityIndicator.startAnimating()
activityIndicator.frame = CGRect(x: CGFloat(0), y: CGFloat(0), width: allOrdersTableV.bounds.width, height: CGFloat(44))
self.tableview.tableFooterView = activityIndicator
self.tableview.tableFooterView?.isHidden = false
isDataLoading = true
startIndex = orders.count
self.loadMoreOrders()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment