2014-12-03 67 views
0

我正在使用集合视图,我在集合视图中显示了一系列图像,现在我需要以更大的尺寸在另一个视图中显示选定的图像。所以我执行如下。实现单个单元格选择以调出详细视图

FUNC的CollectionView(的CollectionView:UICollectionView,numberOfItemsInSection部的: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) 


} 

但是我得到出乎意料地发现零,而在解缠线的可选值fullImageVw.imageFull.image = newCell错误.imageView.image。 但newCell.imageView.image有一个值,我仍然不知道为什么面临这个错误。 任何人都可以帮助我解决这个错误。

回答

0

我通常创建在选择时转到详细信息视图,然后而是采用didSelectItemAtIndexPath的故事情节进行SEGUE我用prepareForSegue像这样

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 

     } 
} 

至于你的具体的问题,我不是真的肯定是什么导致它返回零,但我已经基本上做了你想要做的这种方式多次,它的工作,所以希望它也适用于你。

+0

我它。谢谢!!! – 2014-12-04 20:12:19

0

今天我遇到了同样的问题。 由于您的视图中创建的故事板,但您调用它编程的观点并没有完全在当你打电话的时候呈现 fullImageVw.imageFull.image = newCell.imageView.image

一个修复你可以运行前 fullImageVw.imageFull.image = newCell.imageView.image以这种方式 fullImageVw.view上线fullImageVw.imageFull的ImageView的不会是零,它会正常工作 希望它可以帮助

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