我必须在 tableView 上做复选标记,但是如果我正在滚动并且一个复选标记的单元格不可见并且我向后滚动复选标记消失了。
运行此代码时
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
}
经过一点滚动和复选标记后,打印出来的数组就这么大了……
【真、假、真、真、真、假、假、假、假、假、假、假、假、假、假、假、假、假、假、假、假、假、假】