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]; } 
2
  • You want to load the same image on all 3 UIImageViews? If that's so then just do setImage:forState: for all your image views, not just for the first one. Commented May 15, 2011 at 13:25
  • I want to load 3 different images. So 3 buttons to load the images. - ErikS Commented May 15, 2011 at 19:41

1 Answer 1

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]; } 
Sign up to request clarification or add additional context in comments.

2 Comments

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 ?
Added an edit based on your comment. Does this suit what you need?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.