为什么我的UITableView所选单元格不会显示复选标记附件?

时间:2016-08-22 18:32:13

标签: ios swift uitableview swift3

我正在使用Swift 3并尝试获取一个表格视图单元格以突出显示绿色并在点击时显示一个复选标记。

目前,当我运行应用程序时,我可以选择一个单元格,它将变为浅灰色,一旦我选择另一个,它将变为绿色,但仍然无法显示复选标记。

以下是代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let mySelectedCell = tableView.cellForRow(at: indexPath)
    mySelectedCell?.accessoryType = UITableViewCellAccessoryType.checkmark
    mySelectedCell?.tintColor = UIColor.white
    mySelectedCell?.backgroundColor = green

}

任何建议都将不胜感激。

2 个答案:

答案 0 :(得分:0)

尝试:

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

答案 1 :(得分:-1)

cellForRow不会获取正在显示的单元格,它会为该索引路径创建一个单元格。您需要保留一组选定的索引,然后为该单元格或tableView调用update,并在cellForRow中添加添加复选标记附件的代码。

相关问题