Storyboard has a component UIImageView * myImageView; To which I want to upload a picture from the gallery, but for some reason it does not work out, a menu with pictures opens, I select a picture and my myImageView does not display it.
Could you tell me more how to save back to the gallery.

Here is the code:

- (IBAction)pushBtnLoad:(id)sender { NSLog (@"pressed Btn Load"); UIImagePickerController *pickerC = [[UIImagePickerController alloc] init]; pickerC.delegate = self; [self presentViewController:pickerC animated:YES completion:nil]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismissViewControllerAnimated:YES completion:nil]; UIImage *gotImage = [info objectForKey:UIImagePickerControllerOriginalImage]; self.myImageView.image = gotImage; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissViewControllerAnimated:YES completion:nil]; } 
  • one
    and the object in the interface builder exactly points to myImageView? can you set a breakpoint and make sure that gotImage and myImageView are not nil? - Max Mikheyenko
  • The code is working, I just did not connect the UIImageView - I connected it and it all worked. - Volt112

1 answer 1

 (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismissViewControllerAnimated:YES completion:nil]; UIImage *gotImage = info[UIImagePickerControllerOriginalImage]; self.myImageView.image = gotImage; } 
  • Use the {} key or four spaces to indent a lot of line code. - AivanF.