我有一个 scrollToBottom 函数,它通知应用程序何时 beginBatchFetches 获取内容、图片和检查。
//1: User Scrolls all the way down calls beginBatchFetch()
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
let contentHeight = scrollView.contentSize.height
print("offsetY: \(offsetY)")
if offsetY > contentHeight - scrollView.frame.height {
if self.viewSelected == "Content" {
if !contentFetchMore {
beginContentBatchFetch()
}
} else if self.viewSelected == "Pics" {
if !picFetchMore {
beginPicBatchFetch()
}
} else if self.viewSelected == "Checks" {
if !checksFetchMore {
beginChecksBatchFetch()
}
}
}
}
这些是 beginBatchFetchMethods。Self.reload 当前重新加载整个 Tableview:
func beginContentBatchFetch() {
contentFetchMore = true
ProgressHUD.show()
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.checkQueryContinous()
ProgressHUD.dismiss()
}
}
func beginPicBatchFetch() {
picFetchMore = true
ProgressHUD.show()
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.PicContinous()
self.Reload()
ProgressHUD.dismiss()
}
}
func beginChecksBatchFetch() {
checksFetchMore = true
ProgressHUD.show()
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.checkQueryContinous()
self.Reload()
ProgressHUD.dismiss()
}
}
而不是重新加载整个 TableView。我只想重新加载新添加的单元格。例如,如果我在批量获取之前有 10 个单元格,然后在批量获取之后有 20 个单元格,我只想为这些单元格 11-20 重新加载表格视图。
我在网上看了看,StackOverFlow 把我带到了这个:iOS Swift and reloadRowsAtIndexPaths 编译错误
var _currentIndexPath:NSIndexPath?
if let indexPath = _currentIndexPath {
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation:
UITableViewRowAnimation.None)
}
else {
` //_currentIndexPath` is nil.
// Error handling if needed.
}
据我了解,这只会重新加载显示的单元格。但是,我的批处理可能不会返回更多值。结果,我的 tableview 将显示与批量获取之前相同的单元格,这将重新加载这些单元格。由于这些单元格之前已加载,我不想浪费数据/搞砸我的表格视图。
我该怎么办,谢谢?