gpt4 book ai didi

ios - UITableView 滚动时复选标记消失

转载 作者:行者123 更新时间:2023-11-30 12:35:34 26 4
gpt4 key购买 nike

我必须在 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

}

经过一点点滚动和复选标记后,打印的数组就是这么大......

[真、假、真、真、真、假、假、假、假、假、假、假、假、假、假、假、假、假、假、假、假、假、假]

最佳答案

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->    UITableViewCell{
var cell : UITableViewCell = .........
if(boolArray[indexPath.row){
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
} else {
cell.accessoryType = UITableViewCellAccessoryType.None
}
}

试试这个代码。

关于ios - UITableView 滚动时复选标记消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42915742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com