当你点击UITableView中的一行时,该行会高亮显示并被选中。是否有可能禁用这个,所以点击一行什么都不做?


当前回答

1-你所要做的就是设置UITableViewCell实例的选择样式:

objective - c:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

斯威夫特2:

cell.selectionStyle = UITableViewCellSelectionStyle.None


斯威夫特3:

cell.selectionStyle = .none

2 -不要实现- tableview:didSelectRowAtIndexPath:在你的表视图中委托或显式地排除你想要没有动作的单元格。

此外,你也可以从故事板。单击表视图单元格,在表视图单元格下的属性检查器中,将Selection旁边的下拉菜单更改为None。

4 -你可以在(iOS) Xcode 9, Swift 4.0中使用下面的代码禁用表格单元格高亮显示

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let cell = tableView.dequeueReusableCell(withIdentifier: "OpenTbCell") as! OpenTbCell
        cell.selectionStyle = .none
        return cell


}

其他回答

你也可以通过在检查面板的选择选项(UITableView属性)中选择NoSelection来禁用界面构建器本身的行选择,如下图所示

你所要做的就是在UITableViewCell实例上设置选择样式:

objective - c:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

斯威夫特2:

cell.selectionStyle = UITableViewCellSelectionStyle.None

Swift 3和4.x:

cell.selectionStyle = .none

此外,确保你没有在你的表视图委托中实现-tableView:didSelectRowAtIndexPath:或者显式地排除你想要没有动作的单元格。

更多信息在这里和这里

你只需要把这段代码放到cellForRowAtIndexPath中

禁用单元格的选择属性:(在点击单元格时)。

cell.selectionStyle = UITableViewCellSelectionStyle.None

你可以在(iOS) Xcode 9, Swift 4.0中使用以下代码禁用表格单元格高亮显示

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let cell = tableView.dequeueReusableCell(withIdentifier: "OpenTbCell") as! OpenTbCell
        cell.selectionStyle = .none
        return cell


}

在UITableViewDataSource协议中,在方法cellForRowAt中添加:

let cell = tableView.dequeueReusableCell(withIdentifier: "YOUR_CELL_IDENTIFIER", for: indexPath)                
cell.selectionStyle = .none
return cell

OR

你可以到故事板>选择单元格>身份检查器>选择,从下拉菜单中选择none。