I have to make checkmarks on a tableView, but if I'm scrolling and one check marked cell is not visible and I scroll back the checkmark disappeared.
While running this code
var boolArray = [Bool]()
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
if cell.accessoryType == UITableViewCellAccessoryType.Checkmark {
cell.accessoryType = UITableViewCellAccessoryType.None
boolArray[indexPath.row] = false
}
else
{
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
boolArray[indexPath.row] = true
}
println(boolArray)
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
boolArray.append(false)
var view = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CellTable")
return view
}
After a little bit scrolling and checkmarking, the printed array is this big...
[true, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…