這是代碼工作正常,但是當我將滾動我的收藏視圖,則另一小區也被選中,例如18個映像可用,首先顯示了六個在運行時,當我將選擇在六個任意一個,然後又選擇了其他2小區i爲什麼另外兩個小區已選定在這裏混淆了,請給我解決如何在集合視圖中選擇單元格?
在這裏,我拿6芯在故事情節主要表現
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout*)self.collectionView.collectionViewLayout;
flowLayout.minimumLineSpacing = 15;
CGFloat availableWidthForCells = CGRectGetWidth(self.collectionView.frame) - flowLayout.sectionInset.left - flowLayout.sectionInset.right - flowLayout.minimumInteritemSpacing *2;
cellWidth = availableWidthForCells /6;
NSLog(@"cellWidth:%f",cellWidth);
flowLayout.itemSize = CGSizeMake(cellWidth, cellWidth);
這是我Didselect而didDeselect方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.layer.cornerRadius = cellWidth/2.0;
cell.layer.backgroundColor = [UIColor blackColor].CGColor;
NSLog(@"INDEXPATH:-%ld",(long)indexPath.row);
}
-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.layer.cornerRadius = cellWidth/2.0;
cell.layer.backgroundColor = [UIColor whiteColor].CGColor;
}
很多感謝您的代碼工作 –