Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating UITableView (NSFetchedResultsControllerDelegate) from background thread using notifications
    text
    copied!<p>I have a UITableView set up as a NSFetchedResultsControllerDelegate. I have a background thread getting data (in a separate managedObjectContext). Both contexts share the same store coordinator. When an object is removed from the background context (after save) I get the following error:</p> <blockquote> <p>An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. <em>*</em> -[NSMutableArray removeObjectAtIndex:]: index 0 beyond bounds for empty array with userInfo (null)</p> </blockquote> <p>I'm adding an observer on the background thread like this:</p> <pre><code> [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didsave:) name:NSManagedObjectContextDidSaveNotification object:[self managedObjectContext]]; </code></pre> <p>and my didsave: implementation is the following:</p> <pre><code> -(void)didsave:(NSNotification *)nofication { MyAppDelegate *myApp = (MyAppDelegate*)[[UIApplication sharedApplication] delegate]; NSManagedObjectContext *mainContext = [myApp managedObjectContext]; [mainContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) withObject:nofication waitUntilDone:YES]; } </code></pre> <p>In the UITableView controller from didChangeContent:</p> <pre><code>case NSFetchedResultsChangeDelete: [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; break; </code></pre> <p>Cannot I mix a fetchControllerDelegate and another background MOcontext, like I'm trying to do?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload