在stackoverflow中阅读了相当多的问题后,我目前仍然找不到答案。
我无法将 ManagedObjectContext 从 appdelegate 传递到我的 tabbarcontroller View 。
在我的 appdelegate.m 我有这个
#import "memoView.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
memoView *mView = (memoView *)navigationController.topViewController;
mView.ObjectContext =[self managedObjectContext];
}
在 memoView.m 中
- (void)viewDidLoad
{
[super viewDidLoad];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"NoteLog" inManagedObjectContext:[self ObjectContext]];
[fetchRequest setEntity:entity];
NSError *error;
self.memoInfo = [ObjectContext executeFetchRequest:fetchRequest error:&error];
//self.title = @"Memo";
[fetchRequest release];
}
错误原因:“+entityForName:找不到实体名称“NoteLog”的 NSManagedObjectModel
我不确定我做错了什么,我对核心数据比较陌生。
任何意见表示赞赏。
最佳答案
我曾经遇到过这个问题并像这样解决了:
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
self. ObjectContext = appDelegate.ManagedObjectContect;
关于iphone - 如何将 ManagedObjectContext 传递给 TabBarViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8752750/