で「エンドレススクロール」を実装しようとしていUICollectionView
ます。
このチュートリアルのようにデータ配列をバッファリングすることでこれを行います
次に、次の方法でdidEndDisplayingCell
ofを実装します。UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
if (self.galleryArray.count > 0) {
NSIndexPath *newIndexPath = indexPath;
if (self.specialHeaderView.bannerView.scrollDirection == left) {
newIndexPath = [NSIndexPath indexPathForItem:indexPath.row - 1 inSection:indexPath.section];
} else if (self.specialHeaderView.bannerView.scrollDirection == right) {
newIndexPath = [NSIndexPath indexPathForItem:indexPath.row + 1 inSection:indexPath.section];
}
if (newIndexPath.row == (self.galleryArray.count - 1)) {
// user is scrolling to the right from the last item to the 'fake' item 1.
// reposition offset to show the 'real' item 1 at the left-hand end of the collection view
newIndexPath = [NSIndexPath indexPathForItem:1 inSection:indexPath.section];
[self.bannerCollectionView scrollToItemAtIndexPath:newIndexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
return;
}
// if (scrollView.contentOffset.x == self.collectionView.frame.size.width) {
if (newIndexPath.row == 0) {
// user is scrolling to the left from the first item to the fake 'item N'.
// reposition offset to show the 'real' item N at the right end end of the collection view
newIndexPath = [NSIndexPath indexPathForItem:([self.galleryArray count] -2) inSection:indexPath.section];
[self.bannerCollectionView scrollToItemAtIndexPath:newIndexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
}
}
}
問題は、メソッドが呼び出され、コレクション ビューがデリゲートメソッドdidEndDisplayingCell
を介してセルを要求するたびに、セルが非表示に戻ることです。CellForItemAtIndexPath
これが私のCellForItemAtIndexPath
実装です:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
SpecialBannerCell *specialBannerCell = (SpecialBannerCell *)[collectionView dequeueReusableCellWithReuseIdentifier:GalleryCellIdentifier forIndexPath:indexPath];
if (specialBannerCell.hidden) {
}
Benefit *benefit = [self.galleryArray objectAtIndex:indexPath.row];
[specialBannerCell.imageBanner setImageWithURL:[NSURL URLWithString:benefit.imageIphoneUrl] placeholderImage:[UIImage imageNamed:@"photo_loader"]];
return specialBannerCell;
}
ここで何が間違っていますか?