我正在尝试将图像从一个视图传递到另一个视图,但是当我运行下面的代码时,它会一直进入“输入此处”的位置。我该如何解决这个问题?
@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
}
}
答案 0 :(得分:1)
更改"发件人:自我" - > "发件人:tap.view"
func imageTapped(tap: UITapGestureRecognizer) {
performSegueWithIdentifier("questionToFullScreen", sender: tap.view)
}
答案 1 :(得分:0)
这可能是问题所在:
而不是:
func imageTapped(img: AnyObject)
{
performSegueWithIdentifier("questionToFullScreen", sender: self)
}
写下这个:
func imageTapped(gesture: UITapGestureRecognizer)
{
performSegueWithIdentifier("questionToFullScreen", sender: self)
}
答案 2 :(得分:0)
您没有发送UIImage
作为发件人。您正在发送tapGestureRecognizer
。
func imageTapped(img: AnyObject)
{
performSegueWithIdentifier("questionToFullScreen", sender: self)
}
sender现在是UITapGestureRecognizer。您无法使用发件人参数发送UIImage。
self
表示触发您的操作的人。在您的情况下,它是tapGestureRecognizer.