gpt4 book ai didi

ios - UICollectionViewCell 中的导出为零

转载 作者:行者123 更新时间:2023-11-28 09:29:34 24 4
gpt4 key购买 nike

我有一个 UICollectionViewCell 定义如下:

import UIKit

class GalleryCellCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var image: UIImageView!

}

当我添加 socket 时,Xcode 会自动将其放入。在我的 UICollectionViewController

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

函数,然后我尝试设置图像。我的代码是

 override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! GalleryCellCollectionViewCell
let imagePackage = imagePackages?[indexPath.item]
let uiImage = imagePackage?.getUIImage()
cell.image.image = uiImage
return cell
}

在调试器的变量查看器中,我可以看到 uiImage 不是 nil。然而,cell.imagenil。为什么会这样?我是否没有在 storyboard 中正确链接它?

最佳答案

您可以使用标签通过另一种方法访问图像。从单元格的界面生成器 (IB) 转到属性选项卡(第三个选项卡)并为图像设置标签(如 5)

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! GalleryCellCollectionViewCell
let imagePackage = imagePackages?[indexPath.item]
let uiImage = imagePackage?.getUIImage()
var cellImg:UIImageView = cell!.viewWithTag(5) as! UIImageView;

cellImg.image = uiImage
return cell
}

关于ios - UICollectionViewCell 中的导出为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41294621/

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