【发布时间】:2016-12-29 09:51:44
【问题描述】:
我正在使用 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
}
任何建议将不胜感激。
【问题讨论】:
-
你在使用自定义的 UITableViewCell 吗?您是否也在验证这个
didSelectRowAt函数是否被调用? -
您是否尝试将
cell.selectionStyle = .none添加到cellForRowAtIndexPath?
标签: ios swift uitableview swift3