私のアプリケーションには複数のView Controllerがあります。私のVehicleListControllerでは、データをコアデータに保存しています。そしてFavouritesControllerでは、コアデータからデータを取り出してテーブルビューで表示しています。コアデータエラーiPhone
コアデータを表示するためにfavouritesControllerテーブルをチェックしているときにこのエラーが発生します。
'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Favouritesdata''
エンティティ名はFavouritesdataです。アプリケーションデリゲート方法didFinishLaunchingWithOptionsにおいて
アプリケーションにおけるfavouritesController
におけるデータ-(void)getData {
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Favouritesdata" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setFetchBatchSize:20];
[request setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"licensePlate" ascending:YES];
NSArray *newArray = [NSArray arrayWithObject:sort];
[request setSortDescriptors:newArray];
NSError *error;
NSMutableArray *results = [[context executeFetchRequest:request error:&error] mutableCopy];
[self setLicensePlateArray:results];
[self.favouritesTable reloadData];
}
そしてcellForRowAtIndexPathで
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILongPressGestureRecognizer *pressRecongnizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tableCellPressed:)];
pressRecongnizer.minimumPressDuration = 0.5f;
[cell addGestureRecognizer:pressRecongnizer];
[pressRecongnizer release];
}
Favouritesdata *favdata = [licensePlateArray objectAtIndex:indexPath.row];
NSLog(@"favdata: %@", favData);
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
cell.textLabel.text =
[self.filteredListItems objectAtIndex:indexPath.row];
}
else{
cell.textLabel.text = [favdata licenseplate];
// [self.licensePlateArray objectAtIndex:indexPath.row];
}
return cell;}
コアデータアクセサをフェッチするfavouritesController.mで
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *user = [defaults objectForKey:@"Username"];
NSString *passwd = [defaults objectForKey:@"Password"];
if ((user != nil) && (passwd != nil)) {
NSLog(@"Data found");
self.progressView = [[Progressbar alloc] initWithNibName:@"Progressbar" bundle:nil];
self.window.rootViewController = self.progressView;
[self.window makeKeyAndVisible];
}
else {
NSLog(@"No data saved");
self.viewController = [[VektorViewController alloc] initWithNibName:@"VektorViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
}
return YES;}
通りです代理人:
- (NSManagedObjectContext *) managedObjectContext {
if (managedObjectContext != nil) {
return managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator: coordinator];
}
return managedObjectContext;}
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
return managedObjectModel;}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory]
stringByAppendingPathComponent: @"LoginTest.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeUrl options:nil error:&error]) {
/*Error for store creation should be handled in here*/
}
return persistentStoreCoordinator;}
- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];}
私は既存のプロジェクトにコアデータを追加しました。今、なぜ私はこのエラーが発生しているのかわかりませんが、私はすべての必要なメソッドとフレームワークを自分のプロジェクトにコピーしたと思います。
誰でも教えてください。
私は私の質問を編集し、コアのアクセサデータを追加してくださいそれを確認してください –