Martin Muldoon
Martin Muldoon

Reputation: 3428

How to enable User Interaction on Disclosure Indicator, but not on UITableViewCell

I have a UITableView with Static cells. I want some off the cells to have a disclosure indicator that segues to another view.

The issue is that if the user inadvertently clicks the body of the cell, rather than the disclosure indicator, the cell changes color (grey), and remains so.

Is it possible to disable user interaction on the cell but not the disclosure?

 override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
            let identifier = tableView.cellForRow(at: indexPath)?.reuseIdentifier as! String
            selectedCellIdentifier = identifier

            switch identifier {
            case "DescriptionCell":
performSegue(withIdentifier: "ShowHelpView", sender: indexPath)
...
}

I can't call tableView.didDeselect because if the user successfully clicks the next disclosure, the first cell remains selected (grey color).

Upvotes: 0

Views: 228

Answers (2)

Christopher Rex
Christopher Rex

Reputation: 392

Change the selection type of the cell to None in the xib or storyboard. Or in the cellForRowAt: you can set it to .none. This will prevent the grey selection state.

If you do not implement the didSelectRow delegate method then there will be no interaction for the cell.

Upvotes: 2

Phillip
Phillip

Reputation: 4306

You could just set cell.selectionStyle = .none in cellForRow:At:.

Upvotes: 0

Related Questions