title: UICollectionView Pagination - How to get the last visible cell
body: <p>I have a <code>UICollectionView</code>, where it contains 2 cells per row. Now, I need to enable paging, where when the last cell of the <code>UICollectionView</code> appears I need to fetch another set of records. How can I get this done. </p>
  
  <pre><code>-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  
          MyCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cc" forIndexPath:indexPath];
  
              if (indexPath.row == [mydictionary count]) {
                  pg = pg +1;
  
                 [self loadtheservice:pg];
  
              }
  
  
  return cell;
  }
  </code></pre>
  
  <p>According to my above code, the <code>[self loadtheservice:pg]</code> gets called many times. I think the reason is that the final cell is being <code>visible</code> for a long and the <code>cellForItemAtIndexPath</code> is calling the load service method. How can I solve this?</p>