我必须显示复选标记我选择用于某些数组值之前,我必须显示数组值1和没有用于0.How做that..check下面的代码的复选标记:
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
}
泰伯维细胞具有附件类型,在tableviewCellForRowAtIndexPath使用此
cell.accessoryType = UITableViewCellAccessoryCheckmark;
告诉你对号如下。
cell.accessoryType = .None
if Intvalues == dict1 as? NSObject {
// I have to show CheckMark
cell.accessoryType = .Checkmark
}
下面是我在我的应用程序已经使用的方法,
如果您正在使用Web服务,然后调用web服务后实现这个逻辑:
这个代码在Web服务调用部分:
for i in 0..<arrNL.count {
let dict = arrNL[i].mutableCopy() as! NSMutableDictionary
dict.setObject("0", forKey: "isChecked")
self.arrNotificationList.addObject(dict)
}
// Here 0 indicates that initially all are uncheck.
现在的cellForRowAtIndexPath经营情况:
let dict = arrNotificationList[indexPath.row] as! NSDictionary
if(dict["isChecked"] as! String == "0") { // Unchecked
cell.btn_CheckUnCheck.setImage(UIImage(named: "uncheck"), forState: UIControlState.Normal)
} else { // Checked
cell.btn_CheckUnCheck.setImage(UIImage(named: "check"), forState: UIControlState.Normal)
}
// in this condition you can manage check uncheck status
现在对于一个按钮的代码,从中我们可以选中或取消它
let dict = arrNotificationList[indexValue] as! NSMutableDictionary
if(dict["isChecked"] as! String == "1") {
dict.setObject("0", forKey: "isChecked")
} else {
dict.setObject("1", forKey: "isChecked")
}
arrNotificationList.replaceObjectAtIndex(indexValue, withObject: dict)
tblView.reloadData()