我创建了一个自定义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
}
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 :(得分:1)
替换
cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath)
使用
cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) as! GridViewCell