0

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

4

1 回答 1

0

我在我的应用程序中遇到了同样的问题。我通过添加以下行来解决这个问题,该行在我的应用程序委托上配置 managedObjectContext。

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

    viewController.managedObjectContext=self.managedObjectContext;
}

在 viewController viewDidLoad 上你想使用 managedObjectContext:

- (void)viewDidLoad {

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


} 

希望这会有所帮助,莎拉

于 2010-04-07T10:42:36.050 回答