0

I have 3 UIImageViews for which I want to load an image. For 1 image this is not a problem, but how do I scale to 3? The code below is what I have right now.

-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:picker animated:YES];

}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];    
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
[my_image_1 setImage:image forState:UIControlStateNormal];

}
ErikS
  • 31
  • 1
  • 5
  • You want to load the same image on all 3 `UIImageView`s? If that's so then just do `setImage:forState:` for all your image views, not just for the first one. – Alexander N. May 15 '11 at 13:25
  • I want to load 3 different images. So 3 buttons to load the images. - ErikS – ErikS May 15 '11 at 19:41

1 Answers1

1

Have you looked at this or this? They seem to be pointing to this resource.

Edit

Based on your comment, I suggest you declare an ivar imageViewToSet in your class and alter your methods in the problem as below,

-(IBAction) getPhoto:(id) sender {
    // Add code to identify the sender(button) via tags or outlets and set imageViewToSet to the mapped imageView through a switch or if statement.
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:picker animated:YES];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];    
    imageViewToSet.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
Community
  • 1
  • 1
Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
  • I did came across these links. I don't want to select multiple images at the same time. In the ViewController I have 3 images and 3 buttons to select the images. Can I somehow pass the 'sender' to the imagePickerController ? – ErikS May 15 '11 at 20:01
  • Added an edit based on your comment. Does this suit what you need? – Deepak Danduprolu May 15 '11 at 20:17