2016-08-22 35 views
2

我在Swift 3中工作,并尝试获取表格视图单元格以突出显示绿色,并在点击时显示复选标记。为什么我的UITableView的选中单元格不显示复选标记附件?

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

下面是代码:

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

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

} 

任何建议,将不胜感激。

+1

是否使用了自定义的UITableViewCell?你还要验证这个'didSelectRowAt'函数被调用吗? –

+0

您是否曾尝试将'cell.selectionStyle = .none'添加到'cellForRowAtIndexPath'? – beyowulf

回答

-1

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

0

尝试:

self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None); 
相关问题