dpstart
dpstart

Reputation: 1088

Tap gesture not detected in UITableViewCell

I'm trying to detect a tap gesture on a UIImageView inside a UITableViewCell.

This is the part of the code inside cellForRowAtIndexPath:

let cell1 : cellTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! cellTableViewCell


        tableView.allowsSelection = false
        cell1.profileImg.userInteractionEnabled = true

        let tappedOnImage = UIGestureRecognizer(target: cell1, action: "tappedOnImage:")

        cell1.profileImg.tag = indexPath.row
        cell1.profileImg.addGestureRecognizer(tappedOnImage)

And here's the function handling the gesture:

func tappedOnImage(sender:UITapGestureRecognizer){


    print("hey")
}

However, nothing is happening when I tap.. any suggestions?

Upvotes: 4

Views: 3166

Answers (1)

drewfus
drewfus

Reputation: 38

It is hard to tell what is wrong without seeing more code, but try this:

let tappedOnImage = UITapGestureRecognizer(target: self, action: "tappedOnImage:")

Upvotes: 1

Related Questions