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


当前回答

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

objective - c:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

斯威夫特2:

cell.selectionStyle = UITableViewCellSelectionStyle.None

Swift 3和4.x:

cell.selectionStyle = .none

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

更多信息在这里和这里

其他回答

swift 3的固定解决方案

cell.selectionStyle = .none

这就是我所使用的,在cellForRowAtIndexPath中编写这段代码。

cell.selectionStyle = UITableViewCellSelectionStyleNone;

在属性检查器中的UITableViewCell的XIB中,将Selection的值设置为None。

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

你可以使用:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

UITableView的row at index path方法。

你还可以用:

[tableView deselectRowAtIndexPath:indexPath animated:NO];

在tableview中didselectrowatindexpath方法。