Если я сделаю следующее, то сэкономит:
- (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"];
но я не хочу создавать экземпляр блока каждый раз, когда кто-то выбирает изображение .... поэтому у меня есть метод сохранения, который устанавливает изображение блока из переменной tempPhoto в UIImage так:
-(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"]; , В отладчике также нет сообщений об ошибках.
Любые предложения или советы будут с благодарностью:)