仅在轻触部分中的其他单元格时取消选择单元格

时间:2016-05-12 07:17:14

标签: swift

我有一个包含两个部分的表视图。第1部分(第2部分)中的每个单元都有一个抽头附件和取消选择方法,用于何时轻敲第1部分中的另一个单元。但是,如果点击0部分中的任何单元格,这也会取消选择当前选定的单元格。

我的代码是:

```{r echo=FALSE,result='asis'}
printSection(c("ABC","DEF","GHI"))
```

如果选择了第1部分中的任何其他单元格,我只想取消选择单元格,并忽略对任何其他部分的取消选择。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

要获得正确的参考,您需要在globalArray中管理引用,如下所示:

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
    .........
    if ( globalArray[indexpath.row][SELECTED_STATE] == SELECTED )
    {
     tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .Checkmark
    }
    else 
    {
   tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .None
    } 
    .........


    }
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    //remove the pre selected state if needed by iterating the array

    globalArray[indexpath.row][SELECTED_STATE] = SELECTED 

    tableView .reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)

}
相关问题