0

我得到错误:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“+entityForName:找不到实体名称“CorePlaylist”的 NSManagedObjectModel

但它在不久前奏效了!didFinishLaunchingWithOptions现在我在终止之前收到错误消息。

我的代码是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    NSLog(@"DID finish launching %@", [self managedObjectContext]);

    PlaylistsViewController *table = [[PlaylistsViewController alloc] init];

    NSManagedObjectContext *context = [self managedObjectContext];

    if (!context) {
        NSLog(@"\nCould not create *context for self");
    }

    table.context = context;

    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];

    return YES;
}

编辑:

-(void) getData {
context = [(ClientAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"CorePlaylist" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setFetchBatchSize:20];
[request setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"playlistid" ascending:YES];

NSArray *newArray = [NSArray arrayWithObject:sort];

[request setSortDescriptors:newArray];

NSError *error;

NSMutableArray *results = [[context executeFetchRequest:request error:&error] mutableCopy];

[self setArr:results];

[self.tableView reloadData];
}
4

1 回答 1

1

确保您的 coreDataModel 文件在项目中,并且您调用的实体拼写正确(区分大小写)。

如果您在您的设备上进行测试,您可能需要完全删除应用程序以再次部署它以防止损坏的数据库问题。

于 2012-05-22T10:01:31.760 回答