LoginSignup
24
24

More than 5 years have passed since last update.

UICollectionViewで最下部までスクロールした場合に「続きを読む」処理をする

Last updated at Posted at 2013-01-19

UICollectionView を使っていて、最下部までスクロールした場合に
続きのコンテンツを読み込む処理を行う。

実装

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    ImageCollectionHeaderView *headerView = nil;

    /*
     中略
     ここでヘッダーの生成を行う
     */

    if ([kind isEqual:UICollectionElementKindSectionFooter])
    {
        // 最下部のセクションの場合
        if (collectionView.numberOfSections == indexPath.section + 1) {
            /*
             続きを読む必要があるのか判定
             NUMBER_OF_SECTIONS : 読み込むべき section の数、無制限ならこの if 文は不要
             */
            if (NUMBER_OF_SECTIONS > indexPath.section) {
                // 続きを読む関数
                [self loadNextPage];
            }
        }
    }
    return headerView;
}

- (void)loadNextPage
{
    // 続きを読む処理を行う
    // この関数は複数回呼ばれるので、フラグを立てておいた方がいい
}

24
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
24