4

我正在嘗試在UITableViewCell內部的UIImageView上檢測點擊手勢。在UITableViewCell中未檢測到點擊手勢

這是代碼的內部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) 

而這裏的處理手勢的功能:

func tappedOnImage(sender:UITapGestureRecognizer){ 


    print("hey") 
} 

然而,當我點擊..任何建議,什麼也沒有發生?

回答

1

這是很難說什麼是錯的,沒有看到更多的代碼,但試試這個:

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

除非你tappedOnImage功能在類cellTableViewCell實現。如果是這種情況,那麼我會嘗試添加該類中的手勢識別器,而不是cellForRowAtIndexPath。 – drewfus

+0

我試過「自我」,它不工作... – dpstart

+0

YEs一切都在cellForRowAtIndexPath – dpstart