以编程方式设置目标时,UITapGestureRecognizer无法正常工作

时间:2018-05-10 14:07:48

标签: ios swift uitapgesturerecognizer

我正在尝试在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用户互动

0 个答案:

没有答案