简体   繁体   English

核心数据不保存图像iPhone应用程序

[英]Core data not saving images iphone app

If i do the following it saves fine: 如果我这样做以下可以节省罚款:

- (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"];

but I dont want to create a box instance everytime someone selects an image.... so i have a save method that will set the box image from the UIImage variable tempPhoto like so: 但是我不想每次有人选择图像时都创建一个盒子实例....所以我有一个保存方法,可以从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];

}

but it crashes on [image setValue:tempPhoto forKey:@"boxImage"]; 但在[image setValue:tempPhoto forKey:@“ boxImage”]上崩溃; . There are no error message in the debugger either. 调试器中也没有错误消息。

Any suggestions or advice would be greatly appreciated :) 任何建议或意见,将不胜感激 :)

So many hours of frustration and code switching all down to a .self 如此多的挫折感和代码切换都变成了.self

I changed tempPhoto to self.tempPhoto :) 我将tempPhoto更改为self.tempPhoto :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM