iOS-自定义TableViewCell中的TapRecograiser工作不正常

iOS-自定义TableViewCell中的TapRecograiser工作不正常,ios,swift,tableview,uitapgesturerecognizer,Ios,Swift,Tableview,Uitapgesturerecognizer,我使用的是Xcode 7测试版,Swift 2 我有一个带有自定义tableViewCell的表视图。在自定义单元格中有一个UIImageView和标签。我也为这个tableViewCell定义了一个testCell类。在图像(表中)中,我添加了UITapRecogniser。我还启用了用户交互 问题:目前表中有3行。当我点击前两行的图片时。什么也没发生。当我单击最后一行中的图像时,操作会在控制台上打印“DEF”。这与行数无关-即使更改为4、5或其他任何值,问题仍然存在。基本上只有最后一行中的图

我使用的是Xcode 7测试版,Swift 2 我有一个带有自定义tableViewCell的表视图。在自定义单元格中有一个UIImageView和标签。我也为这个tableViewCell定义了一个testCell类。在图像(表中)中,我添加了UITapRecogniser。我还启用了用户交互

问题:目前表中有3行。当我点击前两行的图片时。什么也没发生。当我单击最后一行中的图像时,操作会在控制台上打印“DEF”。这与行数无关-即使更改为4、5或其他任何值,问题仍然存在。基本上只有最后一行中的图像被点击。不知道为什么??代码如下:

//Defining custom class for the TableViewCell
class testCell : UITableViewCell{
@IBOutlet weak var testLabel: UILabel!
@IBOutlet weak var testImage: UIImageView!
}

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 3
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! testCell
    cell.testLabel?.text = "ABC"
    cell.testImage?.image = UIImage(named: "Santa")
    return cell

}

@IBOutlet weak var tableView: UITableView!

//TapGestureRecogniser Function
@IBAction func imageTap(sender: AnyObject) {
    print("DEF")
}

将添加手势识别器调用从testCell移动到cellforrowatindexpath

   let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! testCell
    cell.testLabel?.text = "ABC"
    cell.testImage?.image = UIImage(named: "Santa")
    let cellTapRecognizer = UITapGestureRecognizer(target: self, action:Selector("imageTap:"))
    cellTapRecognizer.cancelsTouchesInView = false
    cell.testImage?.addGestureRecognizer(cellTapRecognizer)

将添加手势识别器调用从testCell移动到cellforrowatindexpath。让cell=tableView.dequeueReusableCellWithIdentifier(“cell”,forIndexPath:indexPath)为!testCell cell.testLabel?.text=“ABC”cell.testImage?.image=UIImage(名为:“Santa”)让CellTapRecognitizer=uiTapGestureRecognitizer(目标:self,操作:选择器(“handleTap:”))CellTapRecognitizer.CancellsTouchesinView=false cell.testImage?.AddGestureRecognitizer(CellTapRecognitizer)