Search code examples
swiftuitableviewuibuttontarget

UITableViewCell not work when clicked without UIButton


I am working tableviewcell when clicked. It will not working when I clicked the cell, I don't want use UIButton because of height messed up. Here my code

cell.accessibilityIdentifier = "\(indexPath.section)"
cell.tag = indexPath.row
cell.target(forAction: #selector(reminderClicked), withSender: self)

and

@objc func reminderClicked(_ sender: UITableViewCell) {
   print("\(sender.tag) - \(String(describing: Int(sender.accessibilityIdentifier ?? "0")))")
}

Any idea?


Solution

  • There is a TableViewDelegate function that you can use to check for clicks on the cell.

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {}