Tab bar application with UINavigation Controller MOC not being retained

I created a tab bar application from the template and added a navigation controller to one of the tabs. I have already created this app from the navigation app template already and is working. The reason I am doing it this way is because I need to add a tab bar and thought it would be easier starting by using the tab bar project template and adding the nav controller to it rather than the other way round.

I have copied the data model over from the other project and added the relevant code to where it should be.

The problem I am having is passing the moc from the app delegate to the tab with the nav controller on. Here is a snippet from my applicationDidFinishLaunching method in my app delegate:

(void)applicationDidFinishLaunching:(UIApplication *)application {
[self createEditableCopyOfDatabaseIfNeeded];



Top_BananaTableViewController *top_BananaTableViewController = (Top_BananaTableViewController *)[navigationController topViewController];

top_BananaTableViewController.managedObjectContext = self.managedObjectContext;



// Add the tab bar controller's current view as a subview of the window
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}

Everything seems fine here but when it comes to the fetchedResultsController on my nav controller view it bombs out with:

+entityForName: could not locate an NSManagedObjectModel for entity name 'cards'

When I checked what was set to my managedObjectContext on that view it was null.

I don't know why or where it is loosing it's setting.

Answers


 Top_BananaTableViewController *top_BananaTableViewController =
 (Top_BananaTableViewController *)[navigationController topViewController];

My guess is that either navigationController is nil here, or the returned value from calling the topViewController method is nil.


"+entityForName: could not locate an NSManagedObjectModel for entity name 'cards'" is because you don't have a valid MOC reference.


Need Your Help

JUnit Application Suite Testing

java junit

I am trying to create a junit test suite that will run all of the test suites within the application... - this is what I have and as far as I can find it should work but it keeps telling me that no...

Play Framework 2.3.x ByteChunks MP3 streaming has no playback, is not 'scrollable' in the browser

java audio playframework http-headers streaming

Using Play Framework (version 2.3.x) (Java style), I am trying to serve an .mp3 file to the browser. Since it is a 'large' file I have decided to go with Play's ByteChunks Object, as follows.