【发布时间】:2016-04-24 03:12:50
【问题描述】:
我的代码在通过滚动表加载数据到某一行时出现了一些问题,但我找不到原因。
基本上,我希望表格在滚动到总元素 - 5 时加载接下来的 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()
}
}
【问题讨论】:
标签: swift uitableview tableview reloaddata