gpt4 book ai didi

ios - 无法将类型 'TLPHAsset' 的值分配给类型 'UIImage?'

转载 作者:行者123 更新时间:2023-11-29 05:33:17 25 4
gpt4 key购买 nike

我正在尝试使用this在我的项目中。但是当我尝试将所选图像添加到我的 collectionView 时,它会给出类似的错误

"Cannot assign value of type 'TLPHAsset' to type 'UIImage?'"

在“

cell.pic.image = selectedAssets[indexPath.item]

谁能帮我解决这个问题。谢谢。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell : GalleryCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "GalleryCollectionViewCell", for: indexPath) as! GalleryCollectionViewCell
cell.pic.image = selectedAssets[indexPath.item]
// cell.pic.layer.cornerRadius = 15

return cell

}

最佳答案

您的 selectedAssets 是 TLPHAsset 类型的任何数组,因此如果您需要分配图像,则需要使用 fullResolutionImage 属性。

let asset: TLPHAsset = selectedAssets[indexPath.item]
if let image = asset.fullResolutionImage {
cell.pic.image = image
}

关于ios - 无法将类型 'TLPHAsset' 的值分配给类型 'UIImage?',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57325014/

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