Last active
February 26, 2019 12:45
-
-
Save JarvisTheAvenger/b62eac206f4b23fa085c919f3406c80a to your computer and use it in GitHub Desktop.
This file contains 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 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