Question

I asked this question before already, but never got a good answer, so I ask it again, re-phrased, and hope the problem becomes more clear:

I have a tab bar controller A, embedded in a navigation controller. The first tab contains a table view Controller B, and the second tab contains a view controller C with a core plot. The navigation bar has a + bar button, which modally segues a view controller D, where the user adds a new object/record to core data.

The table view controller D uses a NSFetchedResultsController as its data source, so when the user returns from controller D, the newly created object is displayed in the table view.

However if the user taps the + bar button on the second tab, and creates a new object/record in the modally segued view controller D, and then returns to the second tab, the core plot graph is not updated. I investigated, and found that the fetch request, which supplies the data for the core plot is not updated/executed again.

So, how can I force the fetch request to be executed again?

The code at the end of my 'done' method in view controller D:

MRBMITabBarController *tabController = (MRBMITabBarController *) self.delegate;
NSArray *controllers = tabController.viewControllers;
MRBMIKurveViewController *kurveController = (MRBMIKurveViewController *) [controllers objectAtIndex:1];
kurveController.bmisForPlot = nil;
kurveController.bmisForPlot = [[kurveController fetchBmisForPlot] copy];
[kurveController.graph reloadData];
[kurveController.boundLinePlot reloadData];

[self.delegate dismissViewControllerAnimated:YES completion:nil];

But this does not refresh the plot in view controller C, however the table view in table view controller D is refreshed.

Note: MRBMIKurveViewController is view controller C.

No correct solution

OTHER TIPS

call:

NSError *err = nil;
[managedObjectContext save:&err];

after you did change date

call your reload data methods in viewViewAppear method of controller

Finally I found the solution:

MRBMITabBarController *tabController = (MRBMITabBarController *) self.delegate;
NSArray *controllers = tabController.viewControllers;
MRBMIKurveViewController *kurveController = (MRBMIKurveViewController *) [controllers objectAtIndex:1];

kurveController.bmisForPlot = [[kurveController fetchBmisForPlot] copy];
kurveController.dataForPlot = [kurveController testData3];
[kurveController.boundLinePlot reloadData];

[self.delegate dismissViewControllerAnimated:YES completion:nil];

Basically I call all methods (via delegate) which are involved in creating the data for the plot inside the "done" method of view controller D before dismissing view controller D

Why not use a separate fetchedResultsController on the the core plot view (C) and use this as the data source for the plot. Not sure how the plot works so you may have to call reloadData on it. You may only need to implement the one fetchedResultsController delegate method controllerDidChangeContent to call 'reloadData'.

This way your views are totally independent of each other, the one does not even need to know if the other one exists. Your way D has to know intimate details of C. Now you could have a background thread updating the data and your plot will update itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top