Lazy loading technique for UICollectionView

I have an iOS app that uses a UICollectionView to display a horizontal grid of cells. All I need is a smart way (lazy) to load data when the user reaches the end of my UICollectionView. Code I use:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    GridCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Cell forIndexPath:indexPath];


    /**
     TODO
     - Find a good way to check if the user has reach the end of the grid
     - This next piece of code is for demonstration purposes. A real check has to be
     done yet!!!
     **/

    // releases is my datasource //

    if(indexPath.row == (releases.count - 1)) {
        [self getNextListData];
    }

    return cell; // <-- finally return the cell


}

The problem with this code is: if the user quickly scrolls to the end, he has to scroll back and forth to load more items. This is really not user friendly and I need a better way to load items as needed.

Does anyone have any suggestions?

Thanks in advance.

+5
source share
2 answers

UICollectionView UIScrollView. UIScrollView , UIScrollViewDelegate, , . (, scrollViewDidBeginDecelerating:) , , contentOffset contentSize. ( , % - ), .

scrollview , collectionView:cellForItemAtIndexPath: ( ).

, Apple UITableView, . (, LazyTableImages)

+5

, . , , 10 , . , , .

if (indexPath.row >= [releases count] - 10)
    [self getNextListData];

, , .

, . 1 .

return [releases count] + 1;

.

if (indexPath.row == [releases count])
    return [JLTActivityCell sharedInstance];

, , , , .

+2

All Articles