views:

36

answers:

2

Hi all,

I asked a similar question a while back, but I'm clearly missing something.

I have 2 view controllers - one that displays the data and one where data is edited. In my first controller, I create my object:

thing = [NSEntityDescription insertNewObjectForEntityForName:@"Thing" inManagedObjectContext:managedObjectContext];

thing.DateTime = [NSDate date];
thing.aNumber = [NSNumber numberWithInt:12000];

In the didSelectRowAtIndexPath method, I then create a new controller and add some of this data:

ThingDetailController *thingDetailController = [[ThingDetailController alloc] initwithDateTime:thing.DateTime];

thingDetailController.managedObjectContext = self.managedObjectContext;

[[self navigationController] pushViewController:thingDetailController animated:YES];
[thingDetailController release];

In my initWithDateTime initializer, I assign the DateTime that is passed in to my ThingDetailController.dateTime object:

- (id)initWithDateTime:(NSDate *)dateStamp {

    dateTime = dateStamp;
    return self;
}

When my new controller appears on the screen, that data is present and usable, but any changes I make there are not sent back to the parent controller when I tap the back button in the detail editor controller.

What do I need to do to make this value changeable in that area ?

Thanks in advance,

+1  A: 

Have you think to commit data to your editing view and/or reload your data into your display view.

I may be don't understand your problem, but if you have changed your data into your editing view you must refresh the parent view to see the change.

Yannick L.
My parent controller is registered as a NSFetchedResultsControllerDelegate and I do have the - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { // In the simplest, most efficient, case, reload the table view. [self.tableView reloadData];}method present. My concern is that I believe the way I am passing the variables to the child view is copying them, not passing them by reference, so changes are not being applied to the parent. Would that make sense ?
Anonymouslemming
You may to commit change into your editing view for that changes are effective.Otherwise if it's like the EntityBeans (in Java), if your object is out of the init context the changes are not considerate and you must merge them.
Yannick L.
+1  A: 

The data is updated but the view does not automatically refresh from that data. If your first view controller is a UITableViewController then you should be using a NSFetchedResultsController and using its delegate methods to detect data changes. Otherwise your view has no idea that the data has changed unless you tell it.

Marcus S. Zarra
I'm pretty sure that I am using a NSFetchedResultsController in the parent view, and I do have the controllerDidChangeContent delegate in the ParentController. What else should I be doing ?
Anonymouslemming
Saving the context as the delegate does not fire until a save is called.
Marcus S. Zarra