我有一个uitableview
使用从数组获取数据的自定义单元格。
定制单元有一个uilabel
and an uibutton
(直到uilabel
文本或为文本加载的数组对象 - 为零)。
启动时一切都很好。当我按下uibutton
正在追加数组,新单元格将插入单元格下方。
但是当我滚动时 - 突然uibutton
出现在该条件的其他单元格上uilabel text isEmpty
不是暗示的。
Here is how the whole process looks like
![enter image description here](https://i.stack.imgur.com/elRpF.png)
这是我的 cellForRowAtIndexPath 代码
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell
cell.lblCarName.text = someTagsArray[indexPath.row]
if let text = cell.lblCarName.text where text.isEmpty {
cell.act1.hidden = false
} else {
println("Failed")
}
cell.act1.setTitle(answersdict[answersdict.endIndex - 2], forState:UIControlState.Normal)
cell.act2.setTitle(answersdict.last, forState:UIControlState.Normal)
return cell
}
所以我的一般问题是如何停止重复使用这些自定义单元格?
据我所知,没有直接的方法可以做到这一点reusablecellswithidentifier
很快,但也许这个问题有一些解决方法?
当单元格被重复使用时,它仍然具有上次使用时的旧值。
您必须通过重置显示隐藏控件的标志来准备重用它。
您可以在以下位置执行此操作:tableView:cellForRowAtIndexPath:
或细胞的prepareForReuse
method.
Update:
以下是您可以为 TblCell 添加的示例:
override func prepareForReuse()
{
super.prepareForReuse()
// Reset the cell for new row's data
self.act1.hidden = true
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)