UICollectionView load more data

后端 未结 2 1476
慢半拍i
慢半拍i 2020-12-28 10:36

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

相关标签:
2条回答
  • 2020-12-28 10:45

    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).
    
    0 讨论(0)
  • 2020-12-28 11:05

    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
       }
    }
    
    0 讨论(0)
提交回复
热议问题