Paul Hegarty在他的課後發表了他的代碼的更新版本,它有一個調用來保存CoreData數據庫的代碼!這可能是您的CoreData信息不會持續存在的原因。
他更新注意是:
// should probably saveToURL:forSaveOperation:(UIDocumentSaveForOverwriting)completionHandler: here!
// we could decide to rely on UIManagedDocument's autosaving, but explicit saving would be better
// because if we quit the app before autosave happens, then it'll come up blank next time we run
// this is what it would look like (ADDED AFTER LECTURE) ...
[document saveToURL:document.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:NULL];
所以,你必須在「fetchFlickrDataInDocument」功能添加了「文件saveToURL」線是這樣的:
- (void)fetchFlickrDataIntoDocument:(UIManagedDocument *)document
{
dispatch_queue_t fetchQ = dispatch_queue_create("Flickr fetcher", NULL);
dispatch_async(fetchQ, ^{
NSArray *photos = [FlickrFetcher recentGeoreferencedPhotos];
[document.managedObjectContext performBlock:^{
// perform in the NSMOC's safe thread (main thread)
for (NSDictionary *flickrInfo in photos) {
[Photo photoWithFlickrInfo:flickrInfo inManagedObjectContext:document.managedObjectContext];
// table will automatically update due to NSFetchedResultsController's observing of the NSMOC
}
// should probably saveToURL:forSaveOperation:(UIDocumentSaveForOverwriting)completionHandler: here!
// we could decide to rely on UIManagedDocument's autosaving, but explicit saving would be better
// because if we quit the app before autosave happens, then it'll come up blank next time we run
// this is what it would look like (ADDED AFTER LECTURE) ...
[document saveToURL:document.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:NULL];
// note that we don't do anything in the completion handler this time
}];
});
}
歡迎來到Stack Overflow。請標記作業問題。另外,請注意清楚地提出您的問題。 –
請更具體一點 - 「核心數據似乎不起作用」是什麼意思?錯誤消息,截圖,代碼片段 - 任何信息都是真正的 - 是提出問題的先決條件。我們無法猜測您電腦的設置,或者您的代碼,或者出了什麼問題。如果你想要一個答案,你必須自己提供這些信息。除此之外,請注意,不一定每個人都知道Photomania示例項目是什麼 - 至少,有一個鏈接可以閱讀它。 :) –
抱歉。我已經更新了我的問題,並且我是新來的。感謝您的提示。 :) – angelmacaraig