将uiimage图像网址数据传递到另一个视图

时间:2016-05-01 19:50:50

标签: ios swift segue

我在主VC中有一个集合视图,需要将图像的url数据传递给其他VC

这是我的代码

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
            let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! EventAlbumCustom

            let release = arrayOfRels[indexPath.row]
            cell.pic.sd_setImageWithURL(NSURL(string: release.url))

            return cell
        }

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


            let Dest  = segue.destinationViewController as! EventPhotoFullSize

            if (segue.identifier == "eventphotofullsize") {

                let cell = sender as! UICollectionViewCell
                Dest.imageURL = cell.pic .....??
            }               
        }

找不到单元格的imageview pic和网址

1 个答案:

答案 0 :(得分:0)

您无法找到在您的单元格中声明的属性,因为在prepareForSegue中您将sender转换为UICollectionViewCell而不是您定义的EventAlbumCustom,代码应该是这样的:

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

   let Dest  = segue.destinationViewController as! EventPhotoFullSize

   if (segue.identifier == "eventphotofullsize") {
      let cell = sender as! EventAlbumCustom
      Dest.imageURL = cell.pic
   }               
}

我希望这可以帮到你