ios - 无法让 UIImageView 在 prepareForSegue 中发送

标签 ios xcode swift uiimageview segue

我正在尝试将图像从一个 View 传递到另一个 View ,但是当我运行下面的代码时,它一直在显示“进入此处”的位置输入。我该如何解决这个问题?

@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
     }
}

最佳答案

  1. 更改“img: AnyObject” --> “tap: UITapGestureRecognizer”
  2. 更改“发件人:自己”-->“发件人:tap.view”

    func imageTapped(tap: UITapGestureRecognizer) {
    
        performSegueWithIdentifier("questionToFullScreen", sender: tap.view)
    }
    

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

相关文章:

ios - 核心数据 + swift Int = 崩溃

xcode - 在 Xcode 中移动文件

ios - 界面生成器缩放?

ios swift : return to previous view controller

ios - 如何在 Swift 2 中创建图像叠加层并添加到 MKMapView?

ios - 如何在UIPageViewController最后一页向右滑动时弹出消息?

IOS 应用程序在一段时间未打开后崩溃

ios - swift 3 : Ambiguous use of mutablecopy

objective-c - 以编程方式将 NSTableCellView 和 subview 设置为具有动态宽度

ios - 我如何像在 Instagram 中一样向它添加评论并允许其他用户也对图片发表评论