我在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
}
任何建议,将不胜感激。
是否使用了自定义的UITableViewCell?你还要验证这个'didSelectRowAt'函数被调用吗? –
您是否曾尝试将'cell.selectionStyle = .none'添加到'cellForRowAtIndexPath'? – beyowulf