gpt4 book ai didi

ios - 如何从外部 UICollectionView 更改 UICollectionView 单元格背景颜色

转载 作者:行者123 更新时间:2023-11-29 02:16:10 24 4
gpt4 key购买 nike

我有一个可点击的饼图,每个部分代表 UICollectionView 中的一个单元格。单击饼图部分时,我想更改它对应的单元格的背景颜色。我正在使用以下但没有任何反应。

- (void)pieChart:(XYPieChart *)pieChart didSelectSliceAtIndex:(NSUInteger)index {

NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];

[[self.collectionCategories cellForItemAtIndexPath:path] setBackgroundColor:[UIColor blueColor]];

}

任何想法,谢谢。

最佳答案

我认为问题在于您创建索引路径的方式。您应该这样做(假设您只有一个部分),

 NSIndexPath *path = [NSIndexPath indexPathForItem:index inSection:0];

TableView 或 Collection View 的indexPath需要指定节和行。如果你记录通过上述方法创建的索引路径,你会发现它的长度是2,而你原来的方法,长度只有1。

关于ios - 如何从外部 UICollectionView 更改 UICollectionView 单元格背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28724548/

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