【发布时间】:2021-10-06 20:46:58
【问题描述】:
我将我的 UICollectionView 添加到 UITableViewCell(目标 c),并且数据在 tableview 内的 collectionviews 中正确显示,同一个 collectionview 中的选择按预期工作;我遇到的问题是:
如果用户在 collectionview (a) 中选择一个单元格,则该单元格的标签背景颜色设置为红色
当用户在 collectionview (b) 中选择一个单元格时,该单元格的标签背景色设置为红色,但 collectionview a 中前一个选定单元格的背景色仍然是 红色!
我的问题是如何将 clearColor 设置为上一个选定的单元格?
请帮忙谢谢
nb:collectionview的数据和数量是动态的
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(self.selectedIndex == indexPath.item)
{
cell.label.backgroundColor = [UIColor redColor];
}
else
{
cell.label.backgroundColor=[UIColor clearColor];
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
self.selectedIndex = indexPath.row;
}
【问题讨论】:
标签: ios objective-c uitableview uicollectionview