我是一个与核心数据相关的新手。有没有人可以帮助我提供适当的步骤/教程,展示如何将图像保存到核心数据并检索它们。我已经能够存储字符串数据,但当尝试保存图像时,我的应用程序会崩溃。
保存图片的步骤:
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];