我有一个单元格,我要将其插入到UITableView的顶部。如何确保当用户点击该单元格时,它不会显示蓝色的选中指示器?
我应该在单元格上设置selectedBackgroundView属性并将其设置为透明颜色。这样,当用户点击单元格时,它仍然会被选择,但是不会显示任何选中指示器。
<code>cell.selectedBackgroundView = [[UIView alloc] initWithFrame:CGRectZero];
cell.selectedBackgroundView.backgroundColor = [UIColor clearColor]; </code>
tableView:didSelectRowAtIndexPath:
仍会被调用。如果要实际防止选择,您需要在UITableViewDelegate
上实现tableView:willSelectRowAtIndexPath:
并对不可选择的行返回 nil。 - j bcell.selectionStyle = UITableViewCellSelectionStyle.none
Swift 3 -cell.selectionStyle = UITableViewCellSelectionStyle.none
- Johannes Knustcell.selectionStyle = .none
意思是取消单元格的选中样式。 - spencer.sm