2014-12-03 62 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) 
相關問題