停止重用自定义单元格Swift

我有一个从数组中获取数据的自定义单元的可用uitableview 。 自定义单元格有一个uilabel和一个uibutton (直到uilabel文本或加载文本的数组对象都是零)。

发射一切都很好。 当我按下uibutton数组被添加时,新的单元格被插入单元格下面。

但是当我滚动 – 突然间uibutton出现在其他单元格,其中这个有条件的uilabel text isEmptyuilabel text isEmpty不是暗示的。

这是整个过程的样子 在这里输入图像说明

这是我的代码为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 cellcells标识,但也许有一些解决方法,在这个问题上?

当一个单元格被重用时,它仍然具有以前使用的旧值。

您必须通过重置显示您隐藏的控制权的标志来准备重用。

您可以在tableView:cellForRowAtIndexPath:或单元格的prepareForReuse方法中执行此操作。

更新:

以下是可以添加到TblCell的示例:

 override func prepareForReuse() { super.prepareForReuse() // Reset the cell for new row's data self.act1.hidden = true }