Reputation: 11
I have 3 buttons, and 3 UIImageViews, and all of the buttons open a UIImagePickerController. I want button 1 to open the UIImagePickerController, and then set the selected image to UIImageView 1, and button 2 to open a UIImagePickerController, and set the selected image to UIImageView 2, ect. How can this be done? Thank you!
Upvotes: 1
Views: 264
Reputation: 985
You can set tags (1,2,3
) to your buttons to determine what button is pressed by user. Store this value into some variable and use it later to determine into which UIImageView you need to set UIImage received from UIImagePickerController.
Update. Tags can be set right in Interface Bulder or from code:
button1.tag = 1;
To store current tag use variable in your controller:
@interface NameOfYourController : UIViewController
{
NSInteger currentTag;
}
To get button tag use this in button touch up inside event:
-(void)buttonTap:(UIButton *)sender
{
currentTag = sender.tag;
}
When UIImagePickerController calls media picking finished, use stored tag:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *img = info[UIImagePickerControllerOriginalImage];
if (currentTag==1)
imageView1.image = image;
else if (currentTag==2)
imageView2.image = image;
else if (currentTag==3)
imageView3.image = image;
}
Upvotes: 2