gpt4 book ai didi

ios - 关于 Collection View ,即使我更改角单元格也不会保留背景颜色

转载 作者:行者123 更新时间:2023-11-30 13:04:18 25 4
gpt4 key购买 nike

我正在制作一个包含 6 * 7 个单元格的 Collection View ,尽管我编写的代码可以在声明 UICollectionView 后更改每个单元格的背景颜色;单元格背景颜色保持白色。其他单元格不会返回白色背景颜色。有人能告诉我为什么只有这个单元格不保留其背景颜色的原因吗?

override func viewDidLoad() {
super.viewDidLoad()
let longPressRecognizer = UILongPressGestureRecognizer(target:self, action: #selector(ViewController.longPressAction(_:)))
longPressRecognizer.allowableMovement = 5
longPressRecognizer.minimumPressDuration = 0.5
self.collectionView.addGestureRecognizer(longPressRecognizer)

}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let col = indexPath.section
let row = indexPath.row

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! TimeTableCollectionViewCell
cell.backgroundColor = UIColor.whiteColor()

if !ViewController.colorDictionary.isEmpty {
for (indexPath, color) in ViewController.colorDictionary {
self.collectionView.cellForItemAtIndexPath(indexPath)?.backgroundColor = color
}
}

最佳答案

请调试字典 if 条件。每次单元格从 Collection View 返回时,它都可能会进入 if 语句。

关于ios - 关于 Collection View ,即使我更改角单元格也不会保留背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39566255/

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