views:

37

answers:

2

My 1st view is a tableView (RootViewController). My 2nd view is a tableView whose data depends on an object that is passed from the RootViewController. My 3rd view is a view that has a textField. It also takes the same object that the 2nd view took. That textField holds the name of the passed object. When I change it, save it and go back to the 2nd view it doesn't show the updated info. But when I go to the 1st view it shows it updated and then so does the 2nd view.

I used [self.tableView reloadData]; in the 2nd view's viewWillAppear method but that doesn't work.

When I say I save I do:

if (![context save:&error])
// error stuff

(The context is also being passed through the views via didSelectRowAtIndexPath)

This must be annoyingly simple. At least I hope so. Thanks.

A: 

In your second view, implement the following notification:

- (void)contextDidSave:(NSNotification *)notification
{

  [managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
  [self.tableView reloadData];

}

put the following in the viewDidLoad method:

[[NSNotificationCenter defaultCenter] addObserver:self
                                selector:@selector(contextDidSave:)
                                                 name:@"ContextDidSave" object:nil];

put the following in dealloc:

[[NSNotificationCenter defaultCenter] removeObserver:self];

Now, when you save the data in your textfield, just after saving the context do the following:

[[NSNotificationCenter defaultCenter] postNotificationName:@"ContextDidSave" object:managedObjectContext];

This should work.

unforgiven
Thanks for the effort. It didn't work though. Does this mean I didn't set up my 2nd tableView correctly; even though it's showing me everything else correctly?
tazboy
A: 

In the 2nd view, put the code that loads the data in the viewWillAppear method, not the viewDidLoad method.

tazboy