次のソース ファイルから、画像を読み込んで Core Data に保存し、imageView にも表示しようとしましたが、うまくいきません。
- (IBAction)save:(id)sender
{
NSLog(@"Telling the AddTrackingTVC Delegate that save was tapped on the AddTrackingTVC");
[self.delegate theSaveButtonOnTheAddPlantNoteTVCWasTapped:self];
MyPlant *myTracking = [NSEntityDescription insertNewObjectForEntityForName:@"MyPlant" inManagedObjectContext:self.managedObjectContext];
myTracking.name = nameTextField.text;
myTracking.detail = detailTextField.text;
myTracking.createdDate = [NSDate date];
//myTracking.photo = [NSData ];
[self.managedObjectContext save:nil]; // write data to database
[self.delegate theSaveButtonOnTheAddPlantNoteTVCWasTapped:self];
}
- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// If our device has a camera, we want to take a picture, otherwise, we // just pick from photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; }
else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; }
// This line of code will generate a warning right now, ignore it
[imagePicker setDelegate:self];
// Place image picker on the screen
[self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.currentEntry.photo = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 1.0);
[self dismissViewControllerAnimated:YES completion:nil];
}
では、画像をコアデータに保存できるようにするには、これらの関数をどうする必要がありますか?