我是一个与核心数据相关的新手。任何人都可以帮助我提供正确的步骤/教程,展示如何将图像保存到核心数据及其检索。我已经能够存储字符串数据,但是我的应用程序在尝试保存图像时崩溃。为了节省:
DataEvent *event = (DataEvent *)[NSEntityDescription insertNewObjectForEntityForName:@"DataEvent"
inManagedObjectContext:managedObjectContext];
NSURL *url2 = [NSURL URLWithString:@"xxxxxxxxxxxxxxx SOME URL xxxxxxxxxxxx"];
NSData *data = [[NSData alloc] initWithContentsOfURL:url2];
imageSave=[[UIImage alloc]initWithData:data];
NSData * imageData = UIImageJPEGRepresentation(imageSave, 100.0);
[event setValue:self.imageSave forKey:@"pictureData"];
对于检索:
DataEvent *event = (DataEvent *)[eventsArray objectAtIndex:indexPath.row];
UIImage *image = [UIImage imageWithData:[event valueForKey:@"pictureData"]];
UIImageView *imageViewMainBackGround = [[UIImageView alloc]
CGRect rect3=CGRectMake(0,2,100.0,100.0);
imageViewMainBackGround.frame = rect3;
[cell.contentView addSubview:imageViewMainBackGround];
[imageViewMainBackGround release];