如何在UITableview上隐藏选择?

时间:2009-11-25 11:31:01

标签: iphone

我想禁用点击特定的Cell.it意味着,我想在触摸特定单元格时不显示高亮颜色(选择指示)?请帮忙吗?

2 个答案:

答案 0 :(得分:15)

使用cell.selectionStyle = UITableViewCellSelectionStyleNone;或返回false或在委托方法tableView:willSelectRowAtIndexPath中返回null

答案 1 :(得分:0)

<强>夫特

  

如果您使用的是自定义单元格:

class YourCustomCell: UITableViewCell {
    override func awakeFromNib() {
        setup()
    }

    init() {
        setup()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    fileprivate func setup() {
        self.selectionStyle = .none
    }
}
  

如果您没有使用自定义单元格:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifierID")
    cell.selectionStyle = .none
    return cell
}

奖励:如果您想隐藏小区选择,也不想拨打func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {...},则只需设置cell.isUserInteractionEnabled = false。但是,这不是一个好习惯。