gpt4 book ai didi

ios - UICollectionViewCell 无法将值分配给 CustomCollectionViewCell

转载 作者:行者123 更新时间:2023-11-29 01:27:57 25 4
gpt4 key购买 nike

我创建了一个自定义 UICollectionViewCell 并尝试从 UICollectionView delegate 方法 cellForItemAtIndexPath 中引用它,但我一直收到 Cannot assign value类型为“UICollectionViewCell”的类型为“GridViewCell”

委托(delegate)方法

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

最佳答案

替换

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

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

关于ios - UICollectionViewCell 无法将值分配给 CustomCollectionViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33803630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com