user6639846
user6639846

Reputation:

Pagination in a vertically scrolling UICollectionview, how to manage?

I have called Web services and get no of data off from-data to two-data. I have scrolled the collection view to load more data of I have passed the from-data to two-data. I have been using scroll views, delegates method for using this pagination are managed.

Upvotes: 2

Views: 2390

Answers (3)

cool_jb
cool_jb

Reputation: 259

For Swift

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    let endScrolling = (scrollView.contentOffset.y + scrollView.frame.size.height)
    
    if endScrolling >= scrollView.contentSize.height {
        
        //Manage Pagination
        //from_Post = from_Data + Page_Number; //Like 10, 20 as you define
        //to_Post = to_Data + Page_Number; //Like 10, 20 as you define

        //Called Function for You Performing action
        //[self GetDataFrom:from_Post To:to_Post];            
    }
}

Upvotes: 1

PT Vyas
PT Vyas

Reputation: 704

Set UIScrollView protocol - UIScrollViewDelegate and define the following Method.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
}

For more details in this method : (base on www.developer.apple.com)

Tells the delegate that the scroll view has ended decelerating the scrolling movement.

Declaration (OBJECTIVE-C:)

  • (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

Parameters

scrollView : The scroll-view object that is decelerating the scrolling of the content view.

Discussion

The scroll view calls this method when the scrolling movement comes to a halt. The decelerating property of UIScrollView controls deceleration.

Availability:

Available in iOS 2.0 and later.

For use this code:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    float endScrolling = (scrollView.contentOffset.y + scrollView.frame.size.height);
    if (endScrolling >= scrollView.contentSize.height)
    {
        //Manage Pagination
        from_Post = from_Data + Page_Number; //Like 10, 20 as you define
        to_Post = to_Data + Page_Number; //Like 10, 20 as you define

        //Called Function for You Performing action
        [self GetDataFrom:from_Post To:to_Post];
    }
}

Upvotes: 1

zylenv
zylenv

Reputation: 932

Set the collection view's delegate to self, and implement the methods of UIScrollDelegate like below:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{  
    //Get the page
    NSInteger page = scrollView.contentOffset.x / scrollView.bounds.size.width;   
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (!decelerate) {
        //Get the page
        NSInteger page = scrollView.contentOffset.x / scrollView.bounds.size.width;
    }
}

Upvotes: 0

Related Questions