ErikS
ErikS

Reputation: 31

multiple UIImageViews with UIImagePickers

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];

}

Upvotes: 0

Views: 408

Answers (1)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

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];
}

Upvotes: 1

Related Questions