UICollectionView加载更多数据

bil*_*990 8 cell ios uicollectionview

如果最后一个单元格将显示,我想从服务器获取更多数据,但是UICollectionView没有像UITableview那样的方法-willDisplayCell.所以我不知道这种情况,有人可以告诉我该怎么办,谢谢!

vai*_*_15 22

你可以简单地在里面实现提取操作 -

  (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

并检查条件

 if(indexPath.row==your_array.count-1).
Run Code Online (Sandbox Code Playgroud)


Sou*_*ess 15

你也可以使用scrollview委托,因为uicollectionview继承自uiscrollview,只需实现uiscrollview委托方法:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
Run Code Online (Sandbox Code Playgroud)

并做一些类似的事情:

- (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
   }
}
Run Code Online (Sandbox Code Playgroud)