2015-11-19 22 views
0

我創建了一個自定義的UICollectionViewCell,我試圖從UICollectionViewdelegate方法cellForItemAtIndexPath引用,而且我不斷收到Cannot assign value of type 'UICollectionViewCell' to type 'GridViewCell'UICollectionViewCell不能將值分配給CustomCollectionViewCell

委託方法

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let asset = self.assetsFetchResults[indexPath.item] as! PHAsset 
    var cell = GridViewCell() 

    //Deque an GridViewCell 
    cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) 
    cell.representedAssetIdentifier = asset.localIdentifier 


    return cell 
} 

GridViewCell類

import UIKit 

class GridViewCell: UICollectionViewCell { 

@IBOutlet weak var imageView: UIImageView! 
var thumbnailImage = UIImage() 
var representedAssetIdentifier = NSString() 

override func prepareForReuse() { 
    super.prepareForReuse() 
    self.imageView.image = nil 
} 

//func setThumbnailImage(thumbnailImage: UIImage) { 
// self.imageView.image = thumbnailImage 
//} 
} 
+0

你分配GridViewCell類故事板細胞的身份檢查? –

+0

我已經做到了。並重新檢查,如果我一次又一次 –

+0

var cell:CustomTableViewCell? = tableView.dequeueReusableCellWithIdentifier(「mycell」)爲? CustomTableViewCell 如果細胞==零{ 電池= CustomTableViewCell(風格:UITableViewCellStyle.Subtitle,reuseIdentifier: 「了myCell」) } –

回答

1

替換

cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) 

隨着

cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) as! GridViewCell