Ios8 选定单元格UICollectionView的IndexPath

Ios8 选定单元格UICollectionView的IndexPath,ios8,uicollectionview,nsindexpath,Ios8,Uicollectionview,Nsindexpath,我目前正在开发一个UICollectionView,其中显示了各种单元格 到目前为止还不错,但我在选择细胞方面有问题。。。例如,我实现了如下选择方法: - (Void)collectionView:(UICollectionView *) collectionView didSelectItemAtIndexPath:(NSIndexPath *) indexPath {      UICollectionViewCell theCell * = (UICo

我目前正在开发一个UICollectionView,其中显示了各种单元格

到目前为止还不错,但我在选择细胞方面有问题。。。例如,我实现了如下选择方法:

    - (Void)collectionView:(UICollectionView *) collectionView didSelectItemAtIndexPath:(NSIndexPath *) indexPath {
        

          UICollectionViewCell theCell * = (UICollectionViewCell *) [CollectionView cellForItemAtIndexPath: indexPath];

         theCell.backgroundColor = [UIColor orangeColor];
        
}
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"yourCelId" forIndexPath:indexPath];


if (cell.selected) {
     cell.backgroundColor = [UIColor orangeColor]; 
} else {
     cell.backgroundColor = [UIColor clearColor];
}   
问题是,在浏览集合视图时,除了使选定单元格变成橙色外,还创建了其他选择

示例:选择单元格编号7,同时自动选择单元格编号14。。。显然,我不需要这个,但我希望它保持选中状态,只保留7号单元格

我哪里做错了?方法中的indexPath?

有问题

(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
加上这样的东西:

    - (Void)collectionView:(UICollectionView *) collectionView didSelectItemAtIndexPath:(NSIndexPath *) indexPath {
        

          UICollectionViewCell theCell * = (UICollectionViewCell *) [CollectionView cellForItemAtIndexPath: indexPath];

         theCell.backgroundColor = [UIColor orangeColor];
        
}
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"yourCelId" forIndexPath:indexPath];


if (cell.selected) {
     cell.backgroundColor = [UIColor orangeColor]; 
} else {
     cell.backgroundColor = [UIColor clearColor];
}   
发生这种情况是因为单元格被重用,您必须重置所有可以更改的值