I have an uitableview
with a custom cell which gets data from the array.
Custom cell has an uilabel
and an uibutton
(which is not visible until the uilabel
text or the array object which loads for the text - is nil).
On launch everything is fine. When i press the uibutton
the array is being appended, the new cells are being inserted below the cell.
But when i scroll - all of a sudden the uibutton
appears on other cells where this conditional uilabel text isEmpty
is not implied.
Here is how the whole process looks like
Here is my code for 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
}
So my general question is how do i stop the reuse of those custom cells?
As far as i'm aware there is no direct way of doing this on reusablecellswithidentifier
in swift, but maybe there are some workarounds on that issue?
TblCell
add the methodprepareForReuse
. This is called every time the cell is reused. In this method hide anything that is hidden by default. Set labels to be blank etc... – Fan