0

我有 6 个带有标签的图像视图。在图像视图上单击一下,我调用 UIActionSheet 以显示按钮“拍照”和“选择图片”。这一切都很好。在我最终设置所选图像的 imagePickerController 中,我如何知道要更新图片的 Imageview。请让我知道如何传递我的标签值来更新正确的点击图像。

这是我的代码。

viewDidLoad

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self
                                             action:@selector(tappedImage:)];

tapGestureRecognizer.numberOfTapsRequired = 1;
[self.photo1 addGestureRecognizer:tapGestureRecognizer];
[self.photo2 addGestureRecognizer:tapGestureRecognizer];
[self.photo3 addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer setDelegate:self];

轻拍图像

- (void)tappedImage:(UIGestureRecognizer *)sender {
{

    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                              initWithTitle:@"Add a Picture"
                              delegate:self
                              cancelButtonTitle:@"Cancel"
                              destructiveButtonTitle:nil
                              otherButtonTitles:@"Take Picture",@"Select Picture", nil];
            [actionSheet showInView:self.view];

}

}

图像选择器控制器

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[picker dismissModalViewControllerAnimated:YES];
[photo1 setImage:image];

}

目前所有图像都设置为 Photo1 Imageview。

任何帮助将不胜感激。

4

1 回答 1

0

将实例变量添加到您的类以存储所选图像。然后在你的tappedImage:方法中你这样做:

_selectedImage = (UIImageView *)sender.view;

_selectedImage您的实例变量类型在哪里UIImageView *

然后在该imagePickerController方法中,您可以执行以下操作:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    [picker dismissModalViewControllerAnimated:YES];
    [_selectedImage setImage:image];
}
于 2013-03-08T15:46:12.707 回答