滚动到底部作为分页时从 API 加载更多数据的最佳方法
Best way To load more data from API when scrolling to bottom as pagination
我想要在 UITableView 中滚动到底部时根据页码
从 API 获取更多日期
都在用这个方法
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (((scrollView.contentOffset.y + scrollView.frame.size.height) > scrollView.contentSize.height ) && ! isLoadingList){
self. isLoadingList = true
self. loadMoreItemsForList()
}
}
或使用此方法
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// fetch new data if user scroll to the last cell
guard isLoadingIndexPath(indexPath) else { return }
if self.totalItems > orders.count {
fetchNextPage()
}
}
使用func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
方法在滚动到底部时获取更多数据。
我想要在 UITableView 中滚动到底部时根据页码
从 API 获取更多日期都在用这个方法
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (((scrollView.contentOffset.y + scrollView.frame.size.height) > scrollView.contentSize.height ) && ! isLoadingList){
self. isLoadingList = true
self. loadMoreItemsForList()
}
}
或使用此方法
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// fetch new data if user scroll to the last cell
guard isLoadingIndexPath(indexPath) else { return }
if self.totalItems > orders.count {
fetchNextPage()
}
}
使用func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
方法在滚动到底部时获取更多数据。