重复单元格,同时滚动uitableview
问题描述:
我正在开发新闻提要,我正在使用uitableview来显示数据。我synchronically加载在其他线程及使用协议的方法,每个单元中的数据,以显示加载的数据:重复单元格,同时滚动uitableview
func nodeLoaded(node: NSMutableDictionary) {
for var i = 0; i < nodesArray.count; ++i {
if ((nodesArray[i]["id"] as! Int) == (node["id"] as! Int)) {
nodesArray[i] = node
}
}
}
的问题是,当我滚动我的UITableView(而数据synchronically装载),我的一些细胞的重复(8行具有与第一行相同的内容,或者第六行具有与第二行相同的内容)。当我滚动一段时间后(我想在数据加载后),然后一切都变得正常。 我寻找答案,发现我要检查,如果电池是nill在的cellForRowAtIndexPath,但在迅疾我的代码是不同的,那么在客观C:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: NewsCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! NewsCell
var node = nodesArray[indexPath.row] as! NSDictionary
if (node["needLoad"] as! Bool) {
dbHelper.getNode(node["id"] as! Int, hash: node["id"] as! Int, tableName: DbHelper.newsTableName, callback: self)
} else {
cell.id = node["id"] as! Int
cell.titleLabel.text = node["title"] as? String
cell.descriptionLabel.text = node["description"] as? String
cell.imgView.image = WorkWithImage.loadImageFromSD((node["image"] as! String))
}
return cell
}
我也不能检查,如果细胞==零BCS的二进制错误(NewsCell不能为零)。
我该怎么办?谢谢。
答
您似乎已经为UITableViewCell创建了一个单独的类。您的代码存在的问题是您在重新使用时没有重置标签。
Oveeride prepareForReuse方法在您的自定义UITableviewCell类中并重置您的接口。这应该解决这个问题。