从以下源文件中,我尝试加载图像并保存到核心数据并在 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];
}
那么我必须用这些功能做什么才能使其能够将图像保存到核心数据?