【问题标题】:Cannot assign value of type 'TLPHAsset' to type 'UIImage?'无法将类型“TLPHAsset”的值分配给类型“UIImage?”
【发布时间】:2019-08-02 10:50:12
【问题描述】:

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

“无法将 'TLPHAsset' 类型的值分配给类型 '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

    }

【问题讨论】:

    标签: ios swift4.2


    【解决方案1】:

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

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

    【讨论】:

    • 您好,很抱歉打扰您,但是如果您有空闲时间,我可以问一个与TLPhotoPicker 相关的问题,实际上我没有找到任何信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 2022-08-18
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    相关资源
    最近更新 更多