Martin Muldoon Martin Muldoon - 5 months ago 37
Swift Question

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).

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download