title: Core data and TabViewController
body: <p>In my project I'm using a tabBarController, then on one of my tabs, I add a navigation controller.</p>
  
  <p>The problem I'm having is this: If I use this code in the AppDelegate:</p>
  
  <ul>
  <li><p>(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   </p>
  
  <p>// Override point for customization after application launch</p>
  
  <p>[window addSubview:[rootController view]];</p>
  
  <p>[window makeKeyAndVisible];</p>
  
  <p>return YES;
  }
  my tabBar view (which is in the main.xib) comes up, but when I click on the tab for the navigation controller (which is using core data) the app crashes with this error:</p></li>
  </ul>
  
  <p>NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'HotSprings</p>
  
  <p>So, I found this code for the AppDelegate:
  - (void)applicationDidFinishLaunching:(UIApplication *)application {</p>
  
  <pre><code>NSManagedObjectContext *context = [self managedObjectContext];
  if (!context) {
      // Handle the error.
  }
  
  RootViewController *rootViewController = (RootViewController *)[navController topViewController];
  rootViewController.managedObjectContext = self.managedObjectContext;
  
  [window addSubview:[navController view]];
  [window makeKeyAndVisible];
  </code></pre>
  
  <p>}
  But, of course, it loads the navigation controller view and ignores main.xib and the tab bar controller.</p>
  
  <p>So, I need to know how to use this last code, but load the tab bar and main.xib. I tried changing the navController to my rootController (which is my tabBarController property, but it doesn't like the "topViewController", which is associated with the navigation controller.</p>
  
  <p>Thanks, Jaime</p>