iphoneobjective-ccocoa-touchuitableview

How to make a cell on a UITableView not selectable?


I have a cell that I am inserting to the top of a UITableView. How can I make sure that when the user clicks on the cell, it doesn't show the blue selected indicator?


Solution

  • To remove the ability of selecting any table cells, or particular table cells based on the row index, use willSelectRowAt

    func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
    
    
            return nil
        }
    

    To simply remove the UI effect of selecting the element, set the selection style of the UITableViewCell to UITableViewCellSelectionStyleNone

    Swift 5:

    selectionStyle = .none