作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用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/
我正在尝试使用this在我的项目中。但是当我尝试将所选图像添加到我的 collectionView 时,它会给出类似的错误 "Cannot assign value of type 'TLPHAsse
我是一名优秀的程序员,十分优秀!