【发布时间】:2017-07-10 16:41:38
【问题描述】:
我有一个 UITableView 设置几乎可以正常工作,但是如果你快速向上或向下滚动,它会将单元格打乱。我设置标签以反映索引路径,甚至当它开始时
[0,0] [0,1] [0,2] [0,3] [0,4] [0,5] [0,6]
快速上下滑动几次后,单元格看起来像这样
[0,1] [0,6] [0,2] [0,3] [0,4] [0,5] [0,0] [0,1]
我的代码类似如下
import UIKit
class TableViewController : UITableViewController {
var dates: [Date]?
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dates?.count ?? 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: tableViewCell.storyboardID, for: indexPath) as? tableViewCell else { fatalError() }
let date = dates?[indexPath.row]
cell.date = date
cell.delegate = self
cell.cellIndex = indexPath
return cell
}
}
【问题讨论】:
-
你能发布你的整个 tableviewcontroller 类吗?我 99% 确定我知道这里发生了什么,但是如果没有完整的代码,将很难帮助您进行修复。
-
您在何时/何地实际设置单元格内容?我怀疑您在重用单元格时没有正确设置数据。
标签: ios iphone swift tableview cells