我想完成对表格视图单元格中的图像进行录音时的操作。我在情节提要板上设置了轻击手势,但每次触摸单元格时都会读取轻击手势。

当仅粘贴表格视图单元格中的图像时,如何完成轻击手势?

ios - 在uitableViewCell Swift上点击手势-LMLPHP

  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return generalRoomDataArr.count // your number of cell here
    }




    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")

        //Transform Data From ^ to load at the bottom
        tableView.transform = CGAffineTransform (scaleX: 1,y: -1);
        cell?.contentView.transform = CGAffineTransform (scaleX: 1,y: -1);
        cell?.accessoryView?.transform = CGAffineTransform (scaleX: 1,y: -1);

        //Set username label to display username
        let usernameLabel = cell?.viewWithTag(1) as! UILabel
        usernameLabel.text = generalRoomDataArr[indexPath.row].username


        //Set message label to display message
        let messageLabel = cell?.viewWithTag(2) as! UILabel
        messageLabel.text = generalRoomDataArr[indexPath.row].message
        messageLabel.numberOfLines = 0

        //initialize UI Profile Image
        let imageView = cell?.viewWithTag(3) as! UIImageView

        //Make Porfile Image Cirlce
        imageView.layer.cornerRadius = imageView.frame.size.width/2
        imageView.clipsToBounds = true

        //Set timeStampLabel to current time AGO
        let timeStampLabel = cell?.viewWithTag(4) as! UILabel
        timeStampLabel.text = generalRoomDataArr[indexPath.row].timeStamp
        timeStampLabel.numberOfLines = 0


        //Loading and change of Usesrs profile image on chat cell
        let userProfileChatImage = generalRoomDataArr[indexPath.row].photoURL

        //Load profile image(on cell) with URL & Alamofire Library



            let downloadURL = NSURL(string: userProfileChatImage!)
            imageView.af_setImage(withURL: downloadURL as! URL)






        // your cell coding
        return cell!
    }






    @IBAction func userPhotoTaped(_ sender: Any) {

        print("tapped")
    }








}//END CLASS

我也尝试过
let tapped:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector(("TappedOnImage:")))
        tapped.numberOfTapsRequired = 1
        cell?.imageView?.addGestureRecognizer(tapped)

func TappedOnImage(sender: UITapGestureRecognizer){
        print("Elltappy")
    }

最佳答案

您应该这样使用。创建一个自定义单元格,并且必须对图像视图使用isUserInteractionEnabled,并且您可以处理点击的图像或表视图确实选择了操作。

class TestCell: UITableViewCell {

@IBOutlet weak var imageV: UIImageView!

override func awakeFromNib() {
    super.awakeFromNib()
    // You must to use interaction enabled
    imageV.isUserInteractionEnabled = true
    imageV.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageTapped(_:))))
}

func imageTapped(_ sender: UITapGestureRecognizer) {
    print("image tapped")
} }

关于ios - 在uitableViewCell Swift上点击手势,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43358238/

10-11 21:10