核心数据未保存图像的iPhone应用程序
问题描述:
如果我做了以下这节省了罚款:核心数据未保存图像的iPhone应用程序
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {
box = (Box *)[NSEntityDescription insertNewObjectForEntityForName:@"Box" inManagedObjectContext:managedObjectContext];
// create an instance of a Box image, assign that instance to Box
//set that image to the selected image from the picker
BoxImage *image = [NSEntityDescription insertNewObjectForEntityForName:@"BoxImage" inManagedObjectContext:managedObjectContext];
box.boxImage = image;
[image setValue:selectedImage forKey:@"boxImage"];
,但我不希望创建一个框实例每次有人选择图像....所以我有一个保存方法将从可变的UIImage设置tempPhoto的框图像,像这样:
-(IBAction)save
{
box = (Box *)[NSEntityDescription insertNewObjectForEntityForName:@"Box" inManagedObjectContext:managedObjectContext];
self.tempBoxCode = self.codeField.text;
//Set the box attributes
[box setCode:self.tempBoxCode];
BoxImage *image = [NSEntityDescription insertNewObjectForEntityForName:@"BoxImage" inManagedObjectContext:managedObjectContext];
box.boxImage = image;
[image setValue:tempPhoto forKey:@"boxImage"];
//commit this box
NSError *error;
if (![managedObjectContext save:&error]) {
// Handle the error.
}
[self.view removeFromSuperview];
}
但它崩溃上[图像的setValue:tempPhoto forKey:@ “boxImage”]; 。调试器中也没有错误消息。
任何建议或意见,将不胜感激:)
答
挫折和代码的这么多时间都切换到一个.self
我改变tempPhoto到self.tempPhoto :)
在哪里tempPhoto是否定义?它可以作为参数传入吗?另外,你为什么混合风格?您可以像这样在BoxImage上设置图像:image.boxImage = tempPhoto; – gerry3 2009-11-17 10:47:10
噢好吧......我不知道!感谢gerry ......我只是第二个解决了这个问题.....它通过添加self.tempPhoto解决了! – 2009-11-17 11:59:54