Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT: @fluchtpunkt answer is correct. After making a few more updates to my code my solution broke again. Removing the the block that re-fetches the FRC made it all work again.</p> <hr> <p>I'm surprised I didn't figure this out in all my iterative testing (learning) yesterday. I was had run into problems with syncing the core data fetched results with the table view in a nice way - often I'd get the mis-match index (blah blah blah the number of rows (#) must equal the number # plus or minus the number of rows blah blah blah ( 0 inserted: # deleted).. etc).</p> <p>My steps to complete this were as follows:</p> <ol> <li>Perform the soft delete &amp; save</li> <li>set the fetched results controller to nil <code>self.fetchedrResultsController = nil</code></li> <li>Do a new fetch</li> <li>THEN delete the row from the table:</li> </ol> <pre> self.fetchedResultsController = nil; NSError *error = nil; if (![[self fetchedResultsController] performFetch:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } else { [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; } </pre> <p>I really don't know why I didn't figure this out earlier, but it makes so much sense. Fresh eyes? </p> <p>Here's the full picture:</p> <pre> -(void) completeTask: (id) sender { NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]]; NSManagedObject *task = [self.fetchedResultsController objectAtIndexPath:indexPath]; [task setValue:date forKey:@"complete"]; AppController *ac = [AppController sharedAppController]; NSManagedObjectContext *moc = [ac managedObjectContext]; NSError *error = nil; if(![moc save:&error]){ NSLog(@"Uh oh - couldn't save the delete! %@ \n%@",error, [error description]); exit(-1); } else { // Save successful; re-fetch data (background) self.fetchedResultsController = nil; NSError *error = nil; if (![[self fetchedResultsController] performFetch:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } else { //update the table view with row animation [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; } } }</pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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