Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView load more data

I want to fetch more data from server if the last cell will display, but UICollectionView don't have method -willDisplayCell like UITableview. So I have no idea about this situation, can somebody tell me what should I do , thanks!

like image 585
billwang1990 Avatar asked Sep 03 '13 08:09

billwang1990


2 Answers

You can simply implement the fetching operation inside -

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

and check for the condition

 if(indexPath.row==your_array.count-1).
like image 182
vaibhav_15 Avatar answered Oct 06 '22 14:10

vaibhav_15


you can also use the scrollview delegate since uicollectionview inherits from uiscrollview , just implement the uiscrollview delegate method :

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;

and do something like :

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.y == scrollView.contentSize.height - scrollView.frame.size.height)
    {
      //LOAD MORE
      // you can also add a isLoading bool value for better dealing :D
   }
}
like image 36
Soufiane.ess Avatar answered Oct 06 '22 14:10

Soufiane.ess