tableView中的imageView上的UISwipeGesture无法正常工作

时间:2015-07-17 23:06:20

标签: ios swift uiimage tableviewcell

我正在尝试在gesture(left/right)内的UIImageView上添加滑动tableViewCell。我有一切工作,但是,当我swipe(left/right)图像显示变化时,我遇到了麻烦。

以下是我的滑动手势添加到CellForRowAtIndexPath

内的代码
resultsImageFileOne[indexPath.row].getDataInBackgroundWithBlock{
(imageOneData: NSData?, error: NSError?) -> Void in

  if error == nil {
      let imageOne = UIImage(data: imageOneData!)
      //cell.imageView.image = imageOne <- will set image to UIImageView

      self.pictureOne = imageOne //global
  }
}

resultsImageFileTwo[indexPath.row].getDataInBackgroundWithBlock {
(imageTwoData: NSData?, error: NSError?) -> Void in

  if error == nil {
      let imageTwo = UIImage(data: imageTwoData!)
      //cell.imageView.image = imageTwo <- will set image to UIImageView

      self.pictureTwo = imageTwo //global
  }
}

 var swipeLeft = UISwipeGestureRecognizer(target: self, action: "swipeImage:")
 swipeLeft.direction = UISwipeGestureRecognizerDirection.Left

 var swipeRight = UISwipeGestureRecognizer(target: self, action: "swipeImage:")
 swipeRight.direction = UISwipeGestureRecognizerDirection.Right

 cell.mainDrawView.addGestureRecognizer(swipeLeft)
 cell.mainDrawView.addGestureRecognizer(swipeRight)

我的Selector method:它打印出正确的方向,除了我无法从这个外部方法更改单元格内的图像。当滑动发生时,它会崩溃,说它发现没有。

func swipeImage(sender: UISwipeGestureRecognizer){

var newCell: tableViewCell = tableViewCell()

if (sender.direction == .Left){
    println("Swiped Left")

//change image in TableViewCell
newCell.imageView.image = pictureOne
}
if (sender.direction == .Right){        
   println("Swiped Right")
   //change image in TableViewCell
   newCell.imageView.image = pictureOne
  }
}

0 个答案:

没有答案