核心数据有问题吗,因为xcode 4.3.2
我正在按照我在此处
下载文件Stanford Paul Hegarty class for ios 5.0
的核心数据演练进行操作(Video 14 Core data demo)
我运行了它,xcode 4.3.2
但核心数据似乎不起作用,因为tableview
没有出现。我试图在另一台计算机上运行它,xcode 4.2
并且ios 5.0
遇到相同问题的任何人都可以正常工作?我很确定这xcode
是错的。
核心数据有问题吗,因为xcode 4.3.2
我正在按照我在此处
下载文件Stanford Paul Hegarty class for ios 5.0
的核心数据演练进行操作(Video 14 Core data demo)
我运行了它,xcode 4.3.2
但核心数据似乎不起作用,因为tableview
没有出现。我试图在另一台计算机上运行它,xcode 4.2
并且ios 5.0
遇到相同问题的任何人都可以正常工作?我很确定这xcode
是错的。
Paul Hegarty after his class, has published an update version of his code which have a call to SAVE the CoreData database! This may be the reason why your CoreData informations doesn't persist.
His update note was:
// 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];
So, you have to Add the 'document saveToURL' line in the 'fetchFlickrDataInDocument' function like this:
- (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
}];
});
}
有趣的。我遇到了同样的问题,我也在使用 XCode 4.3,但只是认为这是因为你需要的 Flickr 许可证,而我没有。(在FlickAPIKey.h
中,有一个#define FlickrAPIKey @""
,如果您没有该密钥,您将不会下载任何内容。)
更新:我给自己弄了一个 Flickr API 密钥(你可以从他们的网站上获得一个)并尝试了 XCode 4.3 上的 Photomania 应用程序:它就像一个魅力,所以看起来 XCode 不是你的问题。(尽管有时我发现我必须停止并重新启动 XCode 才能摆脱奇怪的错误或编译器错误。)无论如何,在重试之前先删除数据可能是一个想法:在运行之前删除应用程序它和数据库文件也将被删除。
如果有人在使用 Objective-C 时仍然面临同样的问题,那么在获取 API 密钥后您还需要做一件事:将所有内容更改http://
为https://
FlickrFetcher 文件夹中的文件内。这对我有用。