Q:

Implementing single cell selection to bring up a detail view in swift

Am working with Collection View, I displayed array of images in collection view, and now i need to display the selected image in another view in larger size. So i implemented as below.
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return logoImage.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

   let cell : PhotoCollection = collectionView.dequeueReusableCellWithReuseIdentifier("PhotoCells", forIndexPath: indexPath) as PhotoCollection
    cell.imageView.image = logoImage[indexPath.row]
    return cell

}

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    var newCell :PhotoCollection = collectionView.cellForItemAtIndexPath(indexPath) as PhotoCollection
    var fullImageVw : FullImageClass = self.storyboard?.instantiateViewControllerWithIdentifier("FullImage") as FullImageClass
      fullImageVw.imageFull.image = newCell.imageView.image
    self.navigationController?.pushViewController(fullImageVw, animated: true)

}

But am getting the error unexpectedly found nil while unwrapping an Optional value in the line fullImageVw.imageFull.image = newCell.imageView.image.
but newCell.imageView.image has a value still i don't know why am facing this error.
Can anybody help me to solve this error.

A:

I usually create a segue in the storyboard that goes to the detail view when selected and then instead of using didSelectItemAtIndexPath i use prepareForSegue like so
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if (segue.identifier == "DetailSegue"){
            let cell = sender as Cell
            var destination = segue.destinationViewController as DetailViewController

            destination.image = cell.imageView.image

        }
}

As far as your specific problem, I'm not really sure what's causing it to return nil, but I've done essentially what you're trying to do this way many times and it has worked so hopefully it works for you too.

