私は自分のプロジェクト(フォルダ内とxcodeプロジェクトウィンドウ内)にコピーしたあらかじめ設定されたsqliteファイルを持っていますsqliteファイルはtableViewを埋めていませんが、単純なデータでも動作します。 (sqlite、コアデータ、事前設定データ)
sqliteファイルをチェックするとターミナルで、それは正常に動作し、私のsqliteファイルには、適切なデータがあります。
しかし、私はsqliteファイルからのデータで私のtableViewを埋めようとしますが、tableViewはまだ空です。
私はどこを見てくださいか教えていただけますか?
iは最初のいくつかのデータをしようと、それが動作(applicationDidFinishにコメントしているもの...)が、私のsqliteのファイルと、それは動作しません:
ここに私のコードです:(ここでチュートリアルのURL: http://www.raywenderlich.com/980/core-data-tutorial-how-to-preloadimport-existing-data)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSManagedObjectContext *context = [self managedObjectContext];
/*
THIS WORKS :
FailedBankInfo *failedBankInfo = [NSEntityDescription insertNewObjectForEntityForName:@"FailedBankInfo"
inManagedObjectContext:context];
failedBankInfo.name = @"the name";
failedBankInfo.city = @"the city";
failedBankInfo.state = @"the state";
FailedBankDetails *failedBankDetails = [NSEntityDescription insertNewObjectForEntityForName:@"FailedBankDetails"
inManagedObjectContext:context];
failedBankDetails.closeDate = [NSDate date];
failedBankDetails.updatedDate = [NSDate date];
failedBankDetails.zip = [NSNumber numberWithInt:12345];
failedBankInfo.details = failedBankDetails;
failedBankDetails.info = failedBankInfo;
NSError *error;
if (![context save:&error]){
NSLog(@"%@,", [error localizedDescription]);
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FailedBankInfo"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (FailedBankInfo *info in fetchedObjects){
NSLog(@"name : %@", info.name);
FailedBankDetails *details = info.details;
NSLog(@"zip : %@", details.zip);
}
[fetchRequest release];*/
FailedBanksListViewController *root = (FailedBanksListViewController *)[_navController topViewController];
root.context = [self managedObjectContext];
[window addSubview:_navController.view];
[self.window makeKeyAndVisible];
return YES;
}
/** Returns the persistent store coordinator for the application.
If the coordinator doesn't already exist, it is created and the application's store added to it.
*/
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator_ != nil) {
return persistentStoreCoordinator_;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"FailedBanksCD.sqlite"];
/*NSString *storePath = [[self applicationDocumentsDirectory]
stringByAppendingPathComponent: @"FailedBanksCD.sqlite"];
*/
//NSURL *storeURL = [NSURL fileURLWithPath:storePath];
// Put down default db if it doesn't already exist
NSString *storePath = [NSString stringWithFormat:@"%@", storeURL];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle]
pathForResource:@"FailedBanksCD" ofType:@"sqlite"];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}
NSError *error = nil;
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator_;
}
データベースはDOC-dirのにコピーされなかったかのように見える私にはどうもありがとう
ありがとうございます。これは不幸にもテーブルビューを更新しません。 'select * from ZFAILEDBANKINFO limit 3 'というdoc-dirのコピーされたsqliteが入っているかどうか確認すると、端末には何も表示されません。おそらくこれは暗号化されているからです。万が一、自分のコードを見ることができますか?私は、sqliteとxcodeプロジェクトを含むzipファイルをwww.pondb.com(私の個人的なウェブサイト)に入れました。 – Paul
間違ったDBで作業していますか?解凍しようとしているデータは、DB FailedBanksCD.sqliteをコピーしていたときにbanklist.sqlite3にあります。 –
ありがとうott--私は失敗した銀行のsqliteファイルをコピーしたときにそれを混ぜていると思います。あなたの助けてくれてありがとう、乾杯 – Paul