多个按钮 if 语句来分配要调用的 ImageView



我正在尝试有多个UIImageView,每个都有两个按钮 - 一个拍照按钮和一个选择按钮照片。到目前为止,我已经设置了两个UIImageView和四个按钮。当您单击任何"拍照"按钮时,它会对同一过程执行操作:

-(void)takePhoto:(id) sender {
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.sourceType = UIImagePickerControllerSourceTypeCamera;
    [controller setDelegate:self];
    [self presentModalViewController:controller animated:YES];
}

ChoosePhoto Buttons也是如此,它使用SourceTypePhotoLibrary而不是SourceTypeCamera。该过程完成后,它将进入此函数:

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

现在我想我需要一个 if 语句,以便 Xcode 识别正在按下的按钮,以便在您按下第一个图像视图按钮或其他图像视图按钮时它不会同时显示两个图像。我只是不确定这个if语句将包含什么,因为我需要说,如果拍摄照片选择照片isTouchedInside那么它运行第一个ImageView而不是另一个。有什么想法吗?

UIButtons是UIView子类,因此具有标签属性。在每个按钮上设置唯一的标签,并在takePhoto:方法中将该标签保存在iVar中。

 int myTag = ((UIButton *)sender).tag;

然后在您的 didFinish: 方法中检查该 ivar。

相关内容

最新更新