簡體   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