滚动时UITableView Checkmarks消失 [英] UITableView Checkmarks disappear when scrolling

查看:148
本文介绍了滚动时UITableView Checkmarks消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在tableView上制作复选标记,但如果我滚动并且一个检查标记的单元格不可见,我向后滚动复选标记消失。

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.

虽然运行此代码

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]

[true, false, true, true, true, 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
}
}

试试这段代码。

这篇关于滚动时UITableView Checkmarks消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆