禁用uitableview突出显示但允许选择单个单元格

sol*_*hin 77 objective-c uitableview ios

当你点击一个单元格时,行被选中并突出显示.现在我要做的是禁用突出显示但允许选择.它有一个解决方法.有问题可以解决这个问题,但它会禁用选择和突出显示.

Józ*_*sza 164

您可以从Storyboard中将单元格的选择样式设置为"None":

看这里

或者来自代码:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)

对于Swift 3:

cell.selectionStyle = UITableViewCellSelectionStyle.none
Run Code Online (Sandbox Code Playgroud)

对于Swift 4及以上版本:

cell.selectionStyle = .none
Run Code Online (Sandbox Code Playgroud)


tou*_*bun 25

更改UITableViewCellselectedBackgroundView颜色为透明.

    let clearView = UIView()
    clearView.backgroundColor = UIColor.clearColor() // Whatever color you like
    UITableViewCell.appearance().selectedBackgroundView = clearView
Run Code Online (Sandbox Code Playgroud)

或设置特定单元格:

cell.backgroundView = clearView


小智 8

尝试将单元格选择样式设置为无 -

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
Run Code Online (Sandbox Code Playgroud)

这将解决您的问题


Eli*_*iko 8

对于Swift 3.0:

cell.selectionStyle = .none
Run Code Online (Sandbox Code Playgroud)


Mel*_*vin 6

对于Swift:

UITableViewCell.selectionStyle = UITableViewCellSelectionStyle.None;

或者当您在swift中子类化单元格时:

class CustomCell : UITableViewCell {

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        selectionStyle = .None
    }

}
Run Code Online (Sandbox Code Playgroud)


Sai*_*ddy 5

迅速3

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
}
Run Code Online (Sandbox Code Playgroud)