我有一个核心数据模型,当我第一次填充核心数据时,我有一个Exhibit实体,有一些属性和一个与ExhibitImage实体的一对多关系
ExhibitImage *exhibitImage = [ExhibitImage init];
exhibitImage.filePath = [self loadFile:imageUrl];
exhibitImage.exhibit = thisExhibit;//this exhibit is a method arguement of type Exhibit*
UIImage *img = [UIImage imageWithContentsOfFile:[[thisExhibit.exhibitImages anyObject] filePath]];
然后我保存核心数据
+ (BOOL) saveManagedObjectContext
{
NSError *error = nil;
if (![MOC save:&error]) {
NSLog(@"Core Data Save Error: %@, %@", error, [error userInfo]);
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Data Save Failure", @"The application failed to save data to the database")
message:error.localizedDescription
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"BUTTON: OK")
otherButtonTitles: nil];
[errorAlertView show];
return NO;
}
NSLog(@"CORE DATA SAVED");
return YES;
}
并且可以再次成功访问该关系
UIImage *img = [UIImage imageWithContentsOfFile:[[thisExhibit.exhibitImages anyObject] filePath]];
当我稍后尝试访问该关系时,我得到一个EXC_BAD_ACCESS
NSArray *images = [self.exhibit.exhibitImages allObjects];//EXC_BAD_ACCESS (code=1, address=0x1b)
当我再次运行代码时,在崩溃后,没有设置核心数据,上面的行运行并显示图像!
我不知道为什么会这样,并且已经尝试了我所知道的一切来解决这个问题...... 任何帮助将不胜感激
由于