2009-11-25 79 views
5

我想禁用点击特定的Cell.it意味着,当我们触摸特定的单元格时,我不想显示突出显示颜色(选择指示)?请帮忙吗?如何隐藏对UITableview的选择?

+0

对不起。我找到了解决方案.. [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; – 2009-11-25 11:32:08

回答

15

使用cell.selectionStyle = UITableViewCellSelectionStyleNone;或返回false或返回null代表方法tableView:willSelectRowAtIndexPath

+0

我在故事板中将样式设置为none,但我的分隔线变得狂暴。显然这是由于没有阅读文档,在指定的委托方法中返回nil解决了问题......谢谢你为我节省了一些时间。 – 2014-08-28 16:15:55

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。但是,这不是一个好的做法。