【发布时间】:2019-09-30 05:29:41
【问题描述】:
我有一个 tableView,我使用 DispatchQueue 方法延迟插入 20 行。前 10 行看起来不错。当 Xcode 开始将可重用行出列时,问题从第 11 个开始。在模拟器中,它看起来几乎同时开始插入 2 行(第 11+12,然后第 13+14)。
我想知道为什么会这样。 DispatchQueue 和 tableView.dequeueReusableCell 方法是否冲突?如果是的话,如何正确组织事情?
var numberOfCells = 0
//My TableView
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TextCell")! as UITableViewCell
return cell
}
//Function that inserts rows
func updateTableView(nextPassageID: Int) {
for i in 0...numberOfCells - 1 {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(i)) {
self.numberOfCells += 1
let indexPath = IndexPath(row: i, section: 0)
self.tableView.insertRows(at: [indexPath], with: .fade)
}
}
}
【问题讨论】:
标签: ios swift uitableview grand-central-dispatch