title: Getting loaded vs visible cells on a UITableView or UICollectionView
body: <p>With the introduction of iOS 10, it seems like we're going to have <a href="https://developer.apple.com/videos/play/wwdc2016/219/">prefetching enabled by default on UITableView and UICollectionViews</a>. This means that cells that aren't displayed on the screen are going to be fetched before the user actually sees them.</p>
  
  <p>Here are some relevant methods:</p>
  
  <p><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/">UITableView</a>:</p>
  
  <ul>
  <li><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/cellForRowAtIndexPath:">cellForRowAtIndexPath:</a>: returns "<code>nil</code> if the cell is not visible."</li>
  <li><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instp/UITableView/visibleCells">visibleCells</a>: each item represents "a visible cell in the table view."</li>
  <li><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instp/UITableView/indexPathsForVisibleRows">indexPathsForVisibleRows</a>: each item represents "a visible row in the table view."</li>
  </ul>
  
  <p><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/">UICollectionView</a>:</p>
  
  <ul>
  <li><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/#//apple_ref/occ/instm/UICollectionView/visibleCells">visibleCells</a>: "returns the complete list of visible cells displayed by the collection view."</li>
  <li><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/#//apple_ref/occ/instm/UICollectionView/indexPathsForVisibleItems">indexPathsForVisibleItems</a>: each item represents "a visible cell in the collection view."</li>
  <li><a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/#//apple_ref/occ/instm/UICollectionView/cellForItemAtIndexPath:">cellForItemAtIndexPath:</a>: returns "<code>nil</code> if the cell is not visible."</li>
  </ul>
  
  <p>All these specifically mention "visible" in their descriptions. With the introduction of pre-fetching in iOS 10, how would I distinguish between a cell that was pre-fetched vs. one that is currently visible?</p>
  
  <p>In other words:</p>
  
  <ol>
  <li>How do I get all visible cells?</li>
  <li>How do I get all loaded cells?</li>
  </ol>
  
  <p>It does not look like there are any new APIs on either UITableView or UICollectionView that can help with this.</p>