繁体   English   中英

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

[英]Core data not saving images iphone app

如果我这样做以下可以节省罚款:

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

}

但在[image setValue:tempPhoto forKey:@“ boxImage”]上崩溃; 调试器中也没有错误消息。

任何建议或意见,将不胜感激 :)

如此多的挫折感和代码切换都变成了.self

我将tempPhoto更改为self.tempPhoto :)

暂无
暂无

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

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