Okay, so I let the user add an image in a uiimageView. When I try showing that same image on the previous view controller, (in my case the previous view controller is an image on a cell,) it gives me an error (though it does not say what kind of error it is).
Below is the code from the second view controller in which the user can choose a image (and it displays on that view controller without any problems).
-(void) handleImageGallery
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePicker.delegate = self;
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"], 1);
UIImage *img = [[UIImage alloc] initWithData:dataImage];
[self.imageView setImage:img];
[self.imagePicker dismissViewControllerAnimated:YES completion:nil];
}
Here is the Code on the first ViewController:
- (IBAction)unwindToTableViewController:(UIStoryboardSegue *)sender
{
secondViewController *addVC = (AddViewController *)sender.sourceViewController;
UIImage *showImage = addVC.imageView.image;
//myImage is an already defined NSMutablearray
[myImage insertObject:textImage atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.myTableView beginUpdates];
[self.myTableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.myTableView endUpdates]
}
The code gave me a error, so I added a image to xcode and replaced UIImage *showImage = addVC.imageView.image; with this: NSString *textImage = @"coffee.jpg"; and it gave me that image. But what I want is the image that the user chose in the second view controller to show in the firs one.