嘗試在UICollectionView中選擇多個單元格,並在滾動時選擇變化。爲什麼發生,請指導。 以下是代碼。我試過了。滾動時選擇多個值隨機播放:UICollectionView
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
printf("Selected View index=%d",indexPath.row);
itemPaths = [self.collectionView indexPathsForSelectedItems];
UICollectionViewCell* cell=[self.collectionView cellForItemAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_s.png"]];
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell* cell=[self.collectionView cellForItemAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yellow_seat.png"]];
}
我還應該嘗試什麼。
我在StackOverflow上找到了一個解決方法:在prepareForReuse中將單元格的選中狀態設置爲NO。爲此請參閱http://stackoverflow.com/questions/13556476/uicollectionview-with-multi-select-wont-select-more-than-a-dozen-of-items –
@SAMIR RATHOD在哪裏聲明並調用此方法「準備重用「 –