0
如果我做了以下這節省了罰款:核心數據未保存圖像的iPhone應用程序
- (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];
}
但它崩潰上[圖像的setValue:tempPhoto forKey:@ 「boxImage」]; 。調試器中也沒有錯誤消息。
任何建議或意見,將不勝感激:)
在哪裏tempPhoto是否定義?它可以作爲參數傳入嗎?另外,你爲什麼混合風格?您可以像這樣在BoxImage上設置圖像:image.boxImage = tempPhoto; – gerry3 2009-11-17 10:47:10
噢好吧......我不知道!感謝gerry ......我只是第二個解決了這個問題.....它通過添加self.tempPhoto解決了! – 2009-11-17 11:59:54