在tableview上禁用高亮显示

问题描述 投票:2回答:4

如何在不禁用func的情况下禁用tableview上的高亮显示?我试过这些,现在我不能去另一页。

func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return false
}
ios swift tableview
4个回答
5
投票

将UITableViewCell的selectionStyle属性设置为.None。这将允许选择但阻止默认突出显示行为。


2
投票

在控制器的cellForRowAtIndexPath实现中,将selectionStyle设置为.None,如下所示:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)

    cell.selectionStyle = .None

    // ...

    return cell
}

0
投票

我认为禁用选择应该可以解决问题。

tableView.allowsSelection = false

或者,如果您希望用户能够暂时点击表格,您可以这样做:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    //your code
    tableView.deselectRowAtIndexPath(indexPath)
}

0
投票

第1步:选择您的Tableview单元格

enter image description here

步骤2:之后转到Tableview Cell Properties并设置Tableview Cell Selection“.None”

enter image description here

  • 或者您也可以在您的cellForRowAtIndexPath方法中以编程方式添加“Tablecell.selectionStyle = .none”此代码。
© www.soinside.com 2019 - 2024. All rights reserved.