UICollectionView load more data

a 夏天 提交于 2019-11-28 23:22:43

问题


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!


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/18587570/uicollectionview-load-more-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!