Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios - add loading indicator at the bottom of uicollectionview [closed]

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?

like image 538
vondip Avatar asked Sep 11 '13 13:09

vondip


1 Answers

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;
}
like image 82
Guy Kogus Avatar answered Sep 23 '22 10:09

Guy Kogus