title: UITableView Won't stop scrolling?
body: <p>I am building a feed comprised of <code>UITableViewController</code> + <code>NSFetchedResultsController</code>. </p>
  
  <p>Each cell of the table view displays an image. The feed is configured to show images that have not been seen by the user, i.e. <code>seen == 0</code></p>
  
  <p>I would like to mark each cell as "seen" after the user has seen it. Naturally, I am doing this at: </p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
      Item *item = [_fetchedResultsController objectAtIndexPath:indexPath];
      [[ItemStore sharedInstance] seenItem:item];
  }
  </code></pre>
  
  <p>I would also like my feed to clean up rows once they have been marked seen. I have implemented the following:</p>
  
  <pre><code>- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
         atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
        newIndexPath:(NSIndexPath *)newIndexPath {
  
      UITableView *tableView = self.tableView;
  
      switch(type) {
  
          case NSFetchedResultsChangeInsert:
              [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                               withRowAnimation:UITableViewRowAnimationFade];
              break;
  
          case NSFetchedResultsChangeDelete:
              [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                               withRowAnimation:UITableViewRowAnimationFade];
              break;
  </code></pre>
  
  <p><strong>I am currently seeing a bug where if the user scrolls once, the table will keep scrolling infinitely to the next row. I realized that <code>tableView deleteRowsAtIndexPaths</code> will force the table to scroll 1 forward. As a result, the row that has been past will be marked seen, deleted from the table and the table will scroll down 1 row again.</strong> </p>
  
  <p>Are there anyway to work around this problem? </p>
  
  <p>My ideal goal would be to keep 3-4 rows above the current row and only delete them once they are beyond that range. Of course, I would not want the scroll to scroll by itself due to the deletion. </p>
  
  <p>FULL SOURCE:</p>
  
  <pre><code># pragma mark - NSFetchedResultsControllerDelegate
  
  - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
      [self.tableView beginUpdates];
  }
  
  - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id &lt;NSFetchedResultsSectionInfo&gt;)sectionInfo
             atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
  
      switch(type) {
          case NSFetchedResultsChangeInsert:
              [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
                            withRowAnimation:UITableViewRowAnimationFade];
              break;
  
          case NSFetchedResultsChangeDelete:
              [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
                            withRowAnimation:UITableViewRowAnimationFade];
              break;
      }
  }
  
  - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
      Item *item = [self.fetchedResultsController objectAtIndexPath:indexPath];
      if (item.seen) {
          [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
      }
  }
  
  - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
         atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
        newIndexPath:(NSIndexPath *)newIndexPath {
  
      UITableView *tableView = self.tableView;
  
      switch(type) {
  
          case NSFetchedResultsChangeInsert:
              [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                               withRowAnimation:UITableViewRowAnimationFade];
              break;
  
          case NSFetchedResultsChangeDelete:
              [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                               withRowAnimation:UITableViewRowAnimationFade];
              break;
  
          case NSFetchedResultsChangeUpdate:
              [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
              break;
  
          case NSFetchedResultsChangeMove:
              [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
              [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade];
              break;
  
      }
  }
  
  - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
      [self.tableView endUpdates];
  }
  </code></pre>