我的代碼有一些問題通過滾動表將數據加載到某一行,但我找不到原因。滾動以加載數據。迅速。 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()
}
}