Reputation: 315
I'm trying to have multiple UIImageView
's each with two buttons - A Take Photo button and a Choose Button Photo. So far I have set up the two UIImageView
's and the four buttons. When you click any of the Take Photo buttons it takes the action to the same process:
-(void)takePhoto:(id) sender {
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
[controller setDelegate:self];
[self presentModalViewController:controller animated:YES];
}
The same goes for the ChoosePhoto Buttons with a SourceTypePhotoLibrary instead of SourceTypeCamera. Once that process is completed It then goes into this function:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
theImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 690, 440)];
theImageView.userInteractionEnabled = TRUE;
[layout1 addSubview:theImageView];
[theImageView release];
[theImageView setImage:image];
takePhoto.hidden = YES;
choosePhoto.hidden = YES;
theImageView.clipsToBounds = YES;
imagetwo = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
ImageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 690, 440)];
ImageView2.userInteractionEnabled = TRUE;
[layout2 addSubview:ImageView2];
[ImageView2 release];
[ImageView2 setImage:imagetwo];
takePhoto2.hidden = YES;
choosePhoto2.hidden = YES;
ImageView2.clipsToBounds = YES;
}
Now I think I need an if statement so that Xcode recognises which buttons are being pressed so that it doesn't display both images when you press either the First image views buttons or the other image views buttons. I'm just not sure what this if statement would consist of as I need to say that if takePhoto or choosePhoto isTouchedInside
then it runs the first ImageView and not the other. Any ideas?
Upvotes: 0
Views: 554
Reputation: 12106
UIButtons are UIView subclasses, and therefore have a tag property. Set unique tags on each button, and in your takePhoto: method, save that tag in an iVar.
int myTag = ((UIButton *)sender).tag;
Then check that ivar in your didFinish: method.
Upvotes: 1