Utku Dalmaz Utku Dalmaz - 7 months ago 24
Swift Question

Pass uiimage image url data to another view

I have a collection view in main VC and need to pass image's url data to other VC

here is my code

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 .....??
}
}


Cannot find cell's imageview
pic
and the url

Answer

You cannot find the property declared in your cell because in the prepareForSegue you're casting the sender as UICollectionViewCell instead of the you've defined EventAlbumCustom, your code should like this instead:

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

I hope this help you