0

我创建了一个自定义 UICollectionViewCell 并尝试从UICollectionView delegate方法中引用它cellForItemAtIndexPath并且我不断得到Cannot assign value of type 'UICollectionViewCell' to type 'GridViewCell'

委托方法

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

1 回答 1

1

代替

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

cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) as! GridViewCell
于 2015-11-19T12:59:35.380 回答