我必须在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
}
经过一点滚动和选中标记后,打印出的数组就这么大了。
[true,false,true,true,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false]
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
var cell : UITableViewCell = .........
if(boolArray[indexPath.row){
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
} else {
cell.accessoryType = UITableViewCellAccessoryType.None
}
}
试试这个代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句