gpt4 book ai didi

ios - 如何在 tableview swift 中显示复选标记?

转载 作者:搜寻专家 更新时间:2023-11-01 05:56:35 26 4
gpt4 key购买 nike

我必须在选择某些数组值之前显示复选标记,我必须为数组值 1 显示复选标记,而为 0 不显示复选标记。如何做到这一点..检查下面的代码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.textLabel?.text = AllItems[indexPath.row] as? String
for dict1 in selectedItems
{
if Intvalues == dict1 as? NSObject {
// I have to show CheckMark
}
else if ZeroIntvalues == dict1 as? NSObject
{
// I don’t need to show CheckMark



}
}
cell.textLabel?.textColor = UIColor.whiteColor()
return cell
}

最佳答案

因为@Paulw11 说的原因,你的代码是错误的。每个 tableViewCell 都显示复选标记,因为 for 循环的最后一个对象始终是 1

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.textLabel?.text = AllItems[indexPath.row] as? String
if Intvalues == AllItems[indexPath.row] as? Int {
// I have to show CheckMark
cell.accessoryType = .Checkmark
} else {
cell.accessoryType = .None
}
cell.textLabel?.textColor = UIColor.whiteColor()
return cell
}

关于ios - 如何在 tableview swift 中显示复选标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40782238/

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