开发者

Core data not saving images iphone app

开发者 https://www.devze.com 2022-12-11 10:19 出处:网络
If i do the following it saves fine: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {

If i do the following it saves fine:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {

box = (Box *)[NSEntityDescription insertNewObjectForEntityForName:@"Box" inManagedObjectContext:managedObjectConte开发者_如何学Pythonxt];


    // 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:

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

I changed tempPhoto to self.tempPhoto :)

0

精彩评论

暂无评论...
验证码 换一张
取 消