views:

179

answers:

1

I am working on RSS reader code where articles get downloaded and are viewable offline. The problem is only after all articles are downlaoded the tableview containing headlines gets updated. Core data is used. So everytime NSobjectcontext is saved , [self tableview updatebegins ] is called.The table is getting updated via fetchcontroller core data.

I tried saving NSobjectcontext everytime an article is saved but that is not updating the tableview. I want a mechanism similar to instapaper tableview where articles get saved and tableview gets updated immediately. Please help if you know the solution. Thanks in advance.


Adding code for better understanding

AppDelegate.m contains following code

- (void)feedSuccess:(ZSURLConnectionDelegate*)delegate

  NSManagedObjectContext *moc = [self managedObjectContext];

  CXMLElement *root = [document rootElement];
  CXMLElement *channel = [[root elementsForName:@"channel"] lastObject];

  NSFetchRequest *request = [[NSFetchRequest alloc] init];
  [request setEntity:[NSEntityDescription entityForName:@"FeedItem" inManagedObjectContext:moc]];
   for (CXMLElement *item in [channel elementsForName:@"item"])    
   { 
   // push element in core data and then save context
   //Save context 
    [moc save:&error];
  ZAssert(error == nil, @"Error saving context: %@", [error localizedDescription]);
  }

this triggers the table change code in RootviewController.m

  - (void)controllerWillChangeContent:(NSFetchedResultsController*)controller 
{
  [[self tableView] beginUpdates];
}
A: 

If you use the NSFetchedResults controller, simply use its delegate method

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller;

as follows:

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
// In the simplest, most efficient, case, reload the table view.
    [self.tableView reloadData];
}

Every time you update the underlying NSManagedObjectContext, the table will be automatically updated too.

unforgiven
I tried your code. The function controllerDidChangeContent does get called when element is pushed ( Context is saved ) but the tableview is not getting updated. Please help.
I have added the code for better understanding.