私のコードには、スクロールテーブルで特定の行にデータを読み込む際にいくつかの問題がありますが、その理由を見つけることができませんでした。スクロールしてデータをロードします。迅速。 UITableView
基本的には、要素をスクロールするときに次の10要素を読み込みたいと思っています。たとえば、テーブルに最初に10要素を読み込みたいとします。次に、5番目の要素にヒットすると、11〜20個の要素が読み込まれます。
私の問題は、テーブルを最初に読み込むときに、最初の5つの要素だけを読み込みますが、6-10の間にスペースがあることがわかります。次に、5番目の要素にテーブルをスクロールし、 (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()
}
}