【发布时间】:2015-06-08 10:25:35
【问题描述】:
我有一个UICollectionView 在水平流布局中显示自定义单元格;换句话说,一些内容被放置在屏幕边界之外。
此外,我有一个手势触发 NSNotification 导致我的单元格的某些元素(即主题)发生颜色变化。除了出现在屏幕边界之外的单元格不会全部更新为新的颜色变化之外,一切都运行良好。有没有办法强制他们重绘?
在NSNotification 被触发时调用的函数中,我尝试使用self.collectionView.reloadData()、self.collectionView.setNeedsDisplay() 和self.collectionView.setNeedsLayout 重绘集合视图,但无济于事。我在自定义单元格类的awakeFromNib() 中尝试了列表的最后两个,但没有。
这是我的cellForItemAtIndexPath的代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = popularCollectionView!.dequeueReusableCellWithReuseIdentifier("popular", forIndexPath: indexPath) as! PopularPainting
cell.thumbnail.image = paintings[indexPath.row].paintingImage
cell.name!.text = paintings[indexPath.row].paintingName
cell.price!.setTitle(paintings[indexPath.row].paintingPrice, forState: UIControlState.Normal)
if cell.isDark {
cell.name!.textColor = UIColor(red: 205/255, green: 205/255, blue: 205/255, alpha: 1)
cell.price!.setTitleColor(self.kPaleBlue, forState: .Normal)
self.popularCollectionView.reloadData()
}
return cell
}
有什么建议吗?
注意:滚动到屏幕外内容并重复手势以更改主题效果很好,所以我不知道发生了什么。
【问题讨论】:
-
在其他线程中调用它。尝试使用
performSelectorOnMainThread:方法进行更新。 -
@KarthikSivam 尝试了它的 Swift 替代方案,但也没有用
-
请发布您的
cellForItem:方法代码或您更新集合视图单元格颜色的任何位置。 -
@KarthikSivam 更新了我的问题以添加代码
标签: ios swift uicollectionview uicollectionviewcell