【问题标题】:UITableViewCell not work when clicked without UIButton在没有 UIButton 的情况下单击时 UITableViewCell 不起作用
【发布时间】:2020-06-06 22:12:11
【问题描述】:

单击时我正在工作 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")))")
}

有什么想法吗?

【问题讨论】:

  • tableview 有一个方法 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

标签: swift uitableview uibutton target


【解决方案1】:

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

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

【讨论】:

  • 不工作,你能解释一下我应该在里面放什么吗?我做了简单的“打印(indedPath.row)”,它什么也没做
  • 没关系,我意识到我有 tableview.allowsSelection = false,我应该更改为 true。现在可以了,谢谢。
猜你喜欢
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多