【发布时间】:2017-04-28 19:24:06
【问题描述】:
【问题讨论】:
-
你想要什么?您要更改颜色,还是关闭选择颜色?
-
关闭选择颜色
-
我会选择空白颜色而不禁用选择
标签: ios swift uitableview ios10
【问题讨论】:
标签: ios swift uitableview ios10
在 cellForRowAtIndex 中添加 cell.selectionStyle = .none。这将从该单元格中删除 selectionColor
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath)
// do your cell customisation here..
cell.selectionStyle = .none
return cell
}
【讨论】:
尝试以下方法在用户交互时禁用单元格选择。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "yourCellIdentifier", for: indexPath)
//Method 1: Simply disable the user cell interaction.
cell.userInteractionEnabled = false
//or
//Method 2: use UITableViewCellSelectionStyle to none
cell.selectionStyle = UITableViewCellSelectionStyle.none
return cell
}
【讨论】: