나는 프로젝트 (폴더 및 xcode 프로젝트 창)에 복사 한 잘 채워진 sqlite 파일을 갖고있다.sqlite 파일이 tableView를 채우지 않습니다 - 간단한 데이터로도 작동합니다 -? (sqlite, 코어 데이터, 데이터를 미리 채우기)
내가 sqlite 파일을 확인할 때 터미널, 잘 작동, 내 sqlite 파일에 올바른 데이터가 있습니다.
하지만 그때 내 tableView 데이터를 sqlite 파일에서 채우려 고하지만 tableView 여전히 비어 있습니다.
어디에서 봐야할까요?
(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_;
}
감사는 데이터베이스가 문서-디렉토리에 복사되지 않은 것처럼 보이는 나에게 많은
감사합니다.이 경우 테이블보기가 불쾌하게 새로 고쳐지지 않습니다. 'select * from ZFAILEDBANKINFO limit 3 '을 사용하여 doc-dir에서 복사 된 sqlite가 무엇인지 확인하면 터미널에 아무것도 표시되지 않습니다. 아마도 암호화되어 있기 때문일 수 있습니다. 혹시 제 코드를 살펴볼 수 있습니까? 나는 sqlite와 xcode 프로젝트를 포함하는 zip 파일을 www.pondb.com (내 개인 웹 사이트)에 넣었다. – Paul
잘못된 DB에서 작업하고 있습니까? 압축을 풀려고하는 데이터는 DB FailedBanksCD.sqlite를 복사하는 동안 banklist.sqlite3에 있습니다. –
감사합니다, 오트 - 나는 내가 failbank sqlite 파일을 복사 할 때 그것을 뒤섞어 놓았다고 생각합니다. 왜냐하면 나는 여러 번 시도했기 때문에 그럴 것입니다. 마침내 작동합니다. 도와 줘서 고마워, 건배 – Paul