我正在製作我的第一個IOS應用程序,並使用JSON和核心數據獲取和存儲我的數據。NSDocument不會打開
但由於某種原因,它不會打開它的NSDocument
。這就是我正在做的。
- (void)useDocument
{
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.genkDatabase.fileURL path]]) {
// does not exist on disk, so create it
[self.genkDatabase saveToURL:self.genkDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
NSLog(@"test1");
[self setupFetchedResultsController];
NSLog(@"test12");
[self fetchFlickrDataIntoDocument:self.genkDatabase];
}];
} else if (self.genkDatabase.documentState == UIDocumentStateClosed) {
NSLog(@"test2");
// exists on disk, but we need to open it
[self.genkDatabase openWithCompletionHandler:^(BOOL success) {
NSLog(@"test4");
[self setupFetchedResultsController];
NSLog(@"test5");
}];
} else if (self.genkDatabase.documentState == UIDocumentStateNormal) {
NSLog(@"test3");
// already open and ready to use
[self setupFetchedResultsController];
}
}
- (void)setupFetchedResultsController // attaches an NSFetchRequest to this UITableViewController
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"News"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"News.title" ascending:YES]];
// no predicate because we want ALL the Photographers
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.genkDatabase.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
NSLog(@"test10");
}
當你看我的日誌,你會看到以下內容。
測試2測試4測試10測試5
正如你可以看到它打開它succefully。然後執行方法setupFetchedResultsController
。但之後它突然停止。我沒有得到任何錯誤。
它通常應該做的是去fetchFlickrDataIntoDocument
方法。
有人可以幫我嗎?