UIImageView在prepareForSegue中成为发送

UIImageView在prepareForSegue中成为发送

我试图将图像从一个视图传递到另一个视图,但是当我运行以下代码时,它会一直输入“输入此处”的位置。我该如何解决?

@IBOutlet weak var feedImage: UIImageView!

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let myCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! questionCell

//other code here ...

    myCell.feedImage.tag = indexPath.row
    print(myCell.feedImage.tag)

    let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:Selector("imageTapped:"))
    myCell.feedImage.userInteractionEnabled = true
    myCell.feedImage.addGestureRecognizer(tapGestureRecognizer)
}

func imageTapped(img: AnyObject)
{

    performSegueWithIdentifier("questionToFullScreen", sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "questionToFullScreen" {
        guard let feedImage = sender as? UIImageView else {
        //ENTERING HERE
        return }
        guard let destinationViewController = segue.destinationViewController as? fullScreenImageViewController else { return }

      //send the image to the next view
      destinationViewController.image = resultsArray[feedImage.tag].imageFile
     }
}

最佳答案

更改“ img:AnyObject”->“点击:UITapGestureRecognizer”
更改“发件人:自我”->“发件人:tap.view”

func imageTapped(tap: UITapGestureRecognizer) {

    performSegueWithIdentifier("questionToFullScreen", sender: tap.view)
}

关于ios - 无法让UIImageView在prepareForSegue中成为发送者,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34851260/

10-08 21:06