【发布时间】:2015-02-25 16:37:50
【问题描述】:
我有一个可点击的饼图,每个部分代表 UICollectionView 中的一个单元格。单击饼图部分时,我想更改它对应的单元格的背景颜色。我正在使用以下内容,但没有任何反应。
- (void)pieChart:(XYPieChart *)pieChart didSelectSliceAtIndex:(NSUInteger)index {
NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];
[[self.collectionCategories cellForItemAtIndexPath:path] setBackgroundColor:[UIColor blueColor]];
}
任何想法,谢谢。
【问题讨论】:
-
这段代码与集合视图是否在同一个控制器中?
-
是的,它似乎只是不想互动或做出改变。我已检查以确保它们已连接并且已连接,并且我还尝试在创建单元格时更改单元格颜色(它有效)。
-
您是否检查过(使用日志记录或调试器)[self.collectionCategories cellForItemAtIndexPath:path] 正在返回一个单元格?
-
感谢您的建议,我这样做了,它有助于解决问题。我需要改用以下内容: NSIndexPath *path = [NSIndexPath indexPathForRow:index inSection:0];
-
我正要发布这个作为答案。
标签: ios iphone ios8 uicollectionview