如何在imagePickerController中获取Imageview标签以更新正确的ImageView

时间:2013-03-08 15:36:36

标签: ios uiimagepickercontroller uiactionsheet

我有6张带有标签的Imageview。在一次点击图像视图时,我调用UIActionSheet来显示按钮“Take Pic”& “选择Pic”。这一切都很好。 在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];

tappedImage

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

}

}

imagePickerController

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

}

现在所有图像都被设置为Photo1 Imageview。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

向您的类添加实例变量以存储所选图像。然后在tappedImage:方法中执行:

_selectedImage = (UIImageView *)sender.view;

其中_selectedImageUIImageView *类型的实例变量。

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

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