views:

135

answers:

1

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.

Please help.

A: 
 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.

Shaggy Frog
I have resolved this by placing: Top_BananaAppDelegate *appDelegate = (Top_BananaAppDelegate *)[UIApplication sharedApplication].delegate; self.managedObjectContext = appDelegate.managedObjectContext;in the viewdidload method of TopBananaTableViewController
iamsmug