Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable selection effect when selecting UITableViewCell

How can I disable the selection effect when selecting a particular UITableViewCell?

like image 358
Blue Avatar asked Jan 14 '11 05:01

Blue


People also ask

How to remove selection in tableView Swift?

You need to set the selectionStyle property on the cell: cell. selectionStyle = UITableViewCellSelectionStyle. None in Swift, or cell.

How do I remove a selection style in Swift?

Inside the cellForRowAt indexPath method, on the table view cell, set the selectionStyle to . none .

How do you deselect a row in Swift?

deselectRow(at:animated:) Deselects a row that an index path identifies, with an option to animate the deselection.

What is Uitableview in Swift?

A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+


2 Answers

in tableView:cellForRowAtIndexPath: method

use this

cell.selectionStyle = UITableViewCellSelectionStyleNone

like image 97
Robin Avatar answered Nov 11 '22 12:11

Robin


Swift 3.0

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

The job is done by setting:

cell.selectionStyle = .none

like image 44
Chris Tsitsaris Avatar answered Nov 11 '22 12:11

Chris Tsitsaris