title: Tableview crashes when I scroll up to the top and hold
body: <p>I have a table view that is fed by core data. It works fine except when I scroll back to the top and hold it there. Then the app crashes.
  Any suggestions?
  Thanks</p>
  
  <p>// The Model for this class.
  //
  // When it gets set, we create an NSFetchRequest to get all Photographers in the database associated with it.
  // Then we hook that NSFetchRequest up to the table view using an NSFetchedResultsController.</p>
  
  <pre><code>- (void)setManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
  {
      _managedObjectContext = managedObjectContext;
      if (managedObjectContext) {
          NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"TestResults"];
          request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];
          request.predicate = nil; // all records
  
          self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil];
      } else {
          self.fetchedResultsController = nil;
      }
  }
  
  #pragma mark - UITableViewDataSource
  
  // Uses NSFetchedResultsController's objectAtIndexPath: to find the Photographer for this row in the table.
  // Then uses that Photographer to set the cell up.
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TestResults"];
  
      TestResults *testResult = [self.fetchedResultsController objectAtIndexPath:indexPath];
  
      [self showTestResult:testResult];
  
  
      // show traffic light color
  
  
      NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
      [dateFormatter setDateFormat:@"MM-dd-yy hh:mm a"];
      NSString *theDate = [dateFormatter stringFromDate:testResult.date];
  
      cell.textLabel.text = theDate;
      cell.detailTextLabel.text = testResult.overallPassOrFail;
  
      NSLog(@"overall: %@", testResult.overallPassOrFail);
      NSLog(@"light color: %@", testResult.trafficLightColor);
  
      // retrieve an image
      if ([testResult.trafficLightColor isEqualToString:@"Red"]) {
          self.lightImage = @"Red_Light";
      } else if ([testResult.trafficLightColor isEqualToString:@"Yellow"]) {
          self.lightImage = @"Yellow_Light";
      } else {
          self.lightImage = @"Green_Light";
      }
      NSString *imagefile = [[NSBundle mainBundle] pathForResource:self.lightImage ofType:@"png"];
      self.imageOne = [[UIImage alloc] initWithContentsOfFile:imagefile];
      cell.imageView.image = self.imageOne;
      //
  
      return cell;
  }
  </code></pre>