gpt4 book ai didi

ios - 在被点击的单元格的索引处更改数据源

转载 作者:行者123 更新时间:2023-11-28 06:54:47 25 4
gpt4 key购买 nike

我想在点击 collectionView 的单元格时更改显示图像并隐藏标签。但是随着单元格被重复使用,其他单元格设置为在滚动时显示图像。我怎样才能防止在。我已经开始设置单元格的标签,但我不知道如何继续。

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

println("user tapped on cell number \(indexPath.row)")

let cell = collectionView.cellForItemAtIndexPath(indexPath) as! MyCollectionViewCell

cell.tag = indexPath.row

if (cell.tag == 0) {
one = true

if (cell.myLabel.hidden) {
cell.myLabel.hidden = false
cell.MyImageView.image = nil

}
else {
cell.myLabel.hidden = true
cell.MyImageView.image = UIImage(named:"1")!
}
}

最佳答案

您应该尝试使用单元格具有的 selected 属性,当用户从突出显示的单元格中抬起时,选定状态会切换。然后您可以围绕它设置条件。

    if cell?.selected == true {// do whatever you want}  else{// same do whatever you want}

我认为您不需要设置标签,因为您可以在该方法内部使用 indexPath。

关于ios - 在被点击的单元格的索引处更改数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33967210/

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