views:

44

answers:

1

I have tab bar navigation application and The problem is that in my root controller I am able to set its NSContextManagedObject to the app delegates...However when I try to do the same on the other controller the application freezes...

This only happens in the ViewDidLoad but thats where I need to set it so I can fetch the data

Im accessing it like this but it works on the RootviewController:
MyAppDelegate appD = (MyAppDelegate)[[UIApplication sharedApplication] delegate]; managedObjectContext = appD.managedObjectContext

Just does not work when I use it on other view controllers

A: 

Hi,

I faced the same problem on my application. And I solved this by adding the following line that configures the managedObjectContext on my application delegate.

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

    viewController.managedObjectContext=self.managedObjectContext;
}

and on the viewController viewDidLoad you want to use the managedObjectContext:

- (void)viewDidLoad {

[super viewDidLoad];
MyAppDelegate *delegate=[[UIApplication sharedApplication]delegate];
self.managedObjectContext=delegate.managedObjectContext;


} 

hope this helps, Sarah

Sarah