English 中文(简体)
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:

-(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 :)

问题回答

暂无回答




相关问题
Using QCView and iSight to capture image

I have a QCView that loads a Quartz file which gives you iSights feedback (basically like a QTCaptureView) Everything displays fine The button simply takes a snapshot using the following simple ...

Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Transform rectangular image into trapezoid

In .NET how can I transform an image into a trapezoid. The Matrix class supports rotation, shear, etc, but I can t see a trapezoidal transformation. I m using the usual System.Drawing.* API, but I m ...

Rotate image through Y-axis on web page

What are my options for rotating an image on a web page through the Y-axis? I m not sure if I even have the terminology right. Is this called a rotate or a transform. Most of the searches that I ve ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

Convert from 32-BPP to 8-BPP Indexed (C#)

I need to take a full color JPG Image and remap it s colors to a Indexed palette. The palette will consist of specific colors populated from a database. I need to map each color of the image to it s "...

热门标签