首页 > 解决方案 > 在没有 UIButton 的情况下单击时 UITableViewCell 不起作用

问题描述

单击时我正在工作 tableviewcell。当我单击单元格时它不起作用,我不想使用 UIButton 因为高度搞砸了。这是我的代码

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

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

任何想法?

标签: swiftuitableviewuibuttontarget

解决方案


有一个 TableViewDelegate 函数可用于检查单元格上的点击。

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


推荐阅读