如何在tableview swift中显示复选标记? [英] How to show Checkmark in tableview swift?
本文介绍了如何在tableview swift中显示复选标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在选择某些数组值之前,我必须显示复选标记,我必须显示数组值 1 的复选标记,而 0 则不显示复选标记.如何做到这一点..检查下面的代码:
I have to show check mark before i selected for some array values, i have to show the checkmark for array value 1 and none for 0.How to do that..check the code below:
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 说的原因,你的代码是错误的.由于for
循环的最后一个对象总是1
.
Because of reason @Paulw11 said, your code is wrong. Each tableViewCell is displayed checkmark because the last object of for
loop is always 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
}
这篇关于如何在tableview swift中显示复选标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文