简体   繁体   English

UICollectionView加载更多数据

[英]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. 如果最后一个单元格将显示,我想从服务器获取更多数据,但是UICollectionView没有像UITableview那样的方法-willDisplayCell。 So I have no idea about this situation, can somebody tell me what should I do , thanks! 所以我不知道这种情况,有人可以告诉我该怎么办,谢谢!

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).

you can also use the scrollview delegate since uicollectionview inherits from uiscrollview , just implement the uiscrollview delegate method : 你也可以使用scrollview委托,因为uicollectionview继承自uiscrollview,只需实现uiscrollview委托方法:

- (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
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM