Pergunta

A test app from the Master-Detail w/ core data was not saving data across app closing.

In the MasterViewController.m, I've added two lines to the template method:

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

    NSError *error = nil;
    [self.managedObjectContext save:&error];
}

Data seems to now be saving correctly from detail back to master view and to disk store across app uses. However, I am wondering about the ramifications of using this method.

Having several text fields in the detail view, and wanting a quick way (good time) to save the data back out to the documents directory, is this the best method to perform the save?

I noticed other candidate methods are being called after focus leaves the text field.

  • controller: didChangeObject:
  • controllerDidChangeContent:

What is a good location for what reasons?

Foi útil?

Solução

There's no single right answer. It depends on how your app works and when, in your app, it makes sense to say "OK, let's make sure we don't lose this state". Where this is depends on the app-- it's not like there's one specific method that's always the right place to save state. Generally it's whenever the user has completed a specific action or task that you want to keep around. If your current approach makes sense in your app, then it is the right solution. If not, figure out where it does make sense and save changes there.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top