gpt4 book ai didi

ios - UICollectionView 中的图像未显示更改

转载 作者:搜寻专家 更新时间:2023-10-31 08:28:18 25 4
gpt4 key购买 nike

我有一个包含许多项的 UICollectionView。我将其用于商店,我想在单击时编辑单元格中的内容。当我点击单元格时,只是为了测试,我删除了背景,但是当我点击单元格时它永远不会被删除。当我添加打印功能时,它仍然会打印出来,所以我知道正在调用此方法。

我有一个具有以下功能的 UICollectionView 类:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Shop1CollectionViewCell

cell.clickedOn()
collectionView.reloadItems(at: [indexPath])
}

我有一个单元格类:

class Shop1CollectionViewCell: UICollectionViewCell {

@IBOutlet weak var Label: UIView!

@IBOutlet weak var background: UIImageView!

func clickedOn(){
background.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
}

}

有什么我可以做的,它会更新单元格中的内容。它似乎以某种方式被锁定无法更改,或者正在不断重置图像。

最佳答案

替换这个

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Shop1CollectionViewCell

let cell = collectionView.cellForItem(at: indexPath) as! Shop1CollectionViewCell

由于 dequeueReusableCell 返回另一个单元格而不是您单击的单元格,您也可以将此更改保存到该单元格,以免被其他索引出列

关于ios - UICollectionView 中的图像未显示更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53017549/

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