我知道这没有任何意义,但是我在使用 Core Data 构建并调用 CGRectOffset 的 iPhone 应用程序中遇到了一个非常奇怪的错误。我的 App Delegate 的 didFinishLaunchingWithOptions 方法如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Setup the Managed Object Context
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
// Do something - Like exit
}
//Load up the database form a pList
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"tJournals" ofType:@"plist"];
NSMutableArray *plistJournals = [NSMutableArray arrayWithContentsOfFile:plistPath];
//Create a bunch of journals
for (NSDictionary *journal in plistJournals) {
[TJournal journalWithDictionary:journal inManagedObjectContext:context];
}
NSError *error = nil;
[context save:&error];
// ------ Create the View Controller ------
// The Scrolling List
JournalListVC *jvc = [[JournalListVC alloc] init];
// Adjust for the Status Bar's height
CGRect viewFrame = CGRectOffset(jvc.view.frame, 0.0, 20.0);
jvc.view.frame = viewFrame;
jvc.managedObjectContext = context;
// Add the View Controller to the screen
[self.window addSubview:jvc.view];
[self.window makeKeyAndVisible];
return YES;
}
目前,当我将CGRect 视图框线留在其中时,应用程序崩溃并出现以下错误:
“由于未捕获的异常‘NSInternalInconsistencyException’而终止应用程序,原因:‘+entityForName:找不到实体名称‘TJournal’的 NSManagedObjectModel”
如果我注释掉 CGRect 行,它运行良好。for循环内的调用执行得很好(它将数据写入Core Data DB实体名称TJournal,并且完全按照预期执行。)显然,CGRectOffset不依赖Core Data,所以我猜这个错误是虚假的。但我一辈子都想不通。
我已经尝试清理所有目标,清除模拟器中的数据库等。但似乎没有任何效果。
有任何想法吗?谢谢!