我的代码有一些问题通过滚动表将数据加载到某一行,但我找不到原因。滚动以加载数据。迅速。 UITableView
基本上,我希望表格在滚动到总元素时加载下10个元素 - 例如,我希望表格最初加载10个元素。然后,当它击中第五个元素时,它加载11-20个元素。
我的问题是,当我最初加载表时,它只加载前5个元素,但我可以看到6-10之间有一些空格,然后我滚动表格到第五个元素,它加载下10个元素(6-15)。
let rowPerPage = 10
func refreshResults(){
// append data from server //
self.resultsTitleArray.append(...)
if self.resultsTitleArray.count != 0 {
let minCount = min(rowPerPage, self.productImageArray.count) - 1
self.currentResultsTitleArray += self.resultsTitleArray[0...minCount]
}
self.resultsTable.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return currentResultsTitleArray.count
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let diff = rowPerPage - 5
let currentDiff = currentResultsTitleArray.count - 1 - indexPath.row
if currentResultsTitleArray.count != resultsTitleArray.count && diff == currentDiff {
let minCount = min(resultsTitleArray.count, currentResultsTitleArray.count + rowPerPage as Int) - 1
let next = self.currentResultsTitleArray.count
self.currentResultsTitleArray += self.resultsTitleArray[next...minCount]
resultsTable.reloadData()
}
}