我正在尝试在UIImageView
UITableViewCell
内添加点击事件监听器,因此我在其上添加了UITapGestureRecognizer
并使用了此代码
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
...
cell.editTap.addTarget(self, action: #selector(ProfileTVC.editTapped(sender:)))
//editTap is an UITapGestureRecognizer
...
}
}
func editTapped(sender: UITapGestureRecognizer) {
print("tapped")
if sender.state == UIGestureRecognizerState.ended {
let tapLocation = sender.location(in: self.tableView)
if let tapIndexPath = self.tableView.indexPathForRow(at: tapLocation) {
if fields[tapIndexPath.row].field == "languages_spoken" {
} else if fields[tapIndexPath.row].field == "password" {
} else {
}
}
}
}
但是当我点击我的UIImageView
时,editTapped
没有被调用。此外,还启用了UIImageView
用户互动