【发布时间】:2019-12-03 07:51:04
【问题描述】:
我也面临同样的问题Multiple selections Issue
这是我完成的代码。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
RCCollectionCell* cell = [_channelCollectionView dequeueReusableCellWithReuseIdentifier:@"RC" forIndexPath: indexPath];
cell.layer.cornerRadius = 5.0f;
cell.layer.borderWidth=1.0f;
cell.layer.borderColor=[UIColor lightGrayColor].CGColor;
if (indexPath.row < [_fC count]){
[cell setChannel:_favoriteChannels[indexPath.row]];
[_channelCollectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
} else {
//NSLog(@"Error cell %d requested only %d channels in incident", (int)indexPath.row, (int)[_incident.channels count]);
}
return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
RCCollectionCell* cell = [_channelCollectionView dequeueReusableCellWithReuseIdentifier:@"RC" forIndexPath: indexPath];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
RCCollectionCell* cell = (RCCollectionCell*)[collectionView cellForItemAtIndexPath:indexPath];
Channel* channel = [self getChannelForIndexPath:indexPath];
if ([_upload.channels containsObject:channel.uuid]) {
[_upload.channels removeObject:channel.uuid];
cell.selectedImage.hidden = YES;
} else {
[self.view makeToast:channel.name duration:1.5 position:CSToastPositionCenter];
[_upload.channels addObject:channel.uuid];
cell.selectedImage.hidden = NO;
}
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
}
我的问题是cell.selectedImage.hidden = NO;,当我单击任何单元格并滚动集合视图时,我可以看到另一个单元格也受到 selectedimage.hidden = no 的影响。
请给我一些解决此问题的解决方案。
提前致谢。
编辑:
selectedImage 是我用来检查和取消选中单元格的复选标记图像。
【问题讨论】:
-
在
if部分你需要写cell.selectedImage.hidden = YES; -
使用 UICollectionView 选择的目的是什么?我没有看到任何依赖于所选项目的逻辑
-
@dahiya_boy 我无法理解。你能详细说明一下吗?
-
@TiranUt 我正在使用集合视图来显示水平列表视图,其中包括图像文本和复选标记图像。
-
if条件写什么?
标签: ios objective-c uicollectionview uiimageview uicollectionviewcell