ios - add loading indicator at the bottom of uicol

2019-03-27 19:31发布

in iOS is there any built in support for adding a "loader" (UIActivityIndicator) to a uicollectionview, such that every time a user scroll to the last cell of data he'll see another horizontal subview with the loading indicator?

1条回答
Lonely孤独者°
2楼-- · 2019-03-27 20:21

No, there's no "built in" way. What you'd need to do is have an extra cell that contains a loader. It's fairly trivial to detect when this cell appears, at which point you can start the call to load more data.

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
   return [data count] + 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   UICollectionViewCell *cell;

   if (indexPath.item < [data count])
   {
      cell = ...; // regular cell
   }
   else
   {
      cell = ...; // cell with loading indicator
   }

   return cell;
}
查看更多
登录 后发表回答