title: Occasionally empty tableView using NSFetchedResultsController
body: <p>I have <code>UITableViewController</code> with task items that is hooked to Core Data via <code>NSFetchedResultsController</code> using Apple's template for <code>CoreDataTableViewController</code> (subclass). The TVC opens detailViewController which handles edits and saves.</p>
  
  <p>Sometimes when I have tasks saved in Core Data and EDIT one task and then save it, the detailViewController saves the data and makes back segue to the TVC, but the tableView shows no records at all, it's just empty. When I kill the app and run it again, all tasks appear as they should.</p>
  
  <p>It is very rare behaviour and therefore hard to track and debug. Does anybody have any ideas what is causing the empty tableView in those rare cases?</p>
  
  <p><strong>In DetailVC.m</strong></p>
  
  <pre><code>- (void)save
  {
      if (self.editingTask) {
          [[DataManager sharedInstance] updateItem:self.editingTask withText:self.textField.text date:self.datePicker.date priority:self.segmentedControl.selectedSegmentIndex completed:NO];
      } else {
          [[DataManager sharedInstance] saveNewItem:self.textField.text date:self.datePicker.date priority:self.segmentedControl.selectedSegmentIndex];
      }
      [self.navigationController popViewControllerAnimated:YES];
  }
  </code></pre>
  
  <p><strong>In DataManager.m</strong></p>
  
  <pre><code>- (CoreDataStatus)updateItem:(Task *)editingTask withText:(NSString *)text date:(NSDate *)date priority:(NSUInteger)priority completed:(BOOL)completed
  {
      AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  
      Task *taskToUpdate = editingTask;
      taskToUpdate.due = date;
      taskToUpdate.text = text;
      taskToUpdate.priority = [NSNumber numberWithInteger:priority];
      taskToUpdate.completed = [NSNumber numberWithBool:completed];
  
      // save
      NSError *error = nil;
      [appDelegate.managedObjectContext save:&amp;error];
  
      if (!error) {
  
          [self updateNotificationsAndBadgeCount];
          return Success;
      } else {
          return Error;
      }
  }
  </code></pre>
  
  <p><strong>In TVC.m</strong></p>
  
  <pre><code>- (void)awakeFromNib
  {
      self.managedObjectContext = self.appDelegate.managedObjectContext;
  }
  
  - (void)setManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
  {
      _managedObjectContext = managedObjectContext;
  
      NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Task"];
      request.predicate = [NSPredicate predicateWithFormat:@"completed = %@", [NSNumber numberWithBool:NO]];
      request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"due" ascending:YES]];
  
      self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil];
  }
  </code></pre>
  
  <p><strong>In CoreDataTableViewController.m</strong></p>
  
  <pre><code>- (void)performFetch
  {
      if (self.fetchedResultsController) {
          if (self.fetchedResultsController.fetchRequest.predicate) {
              if (self.debug) NSLog(@"[%@ %@] fetching %@ with predicate: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName, self.fetchedResultsController.fetchRequest.predicate);
          } else {
              if (self.debug) NSLog(@"[%@ %@] fetching all %@ (i.e., no predicate)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName);
          }
          NSError *error;
          BOOL success = [self.fetchedResultsController performFetch:&amp;error];
          if (!success) NSLog(@"[%@ %@] performFetch: failed", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
          if (error) NSLog(@"[%@ %@] %@ (%@)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [error localizedDescription], [error localizedFailureReason]);
      } else {
          if (self.debug) NSLog(@"[%@ %@] no NSFetchedResultsController (yet?)", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
      }
      [self.tableView reloadData];
  }
  </code></pre>