1

我的(Purpose Before ,During, After)Image views上有 3 个。view controller我需要分别为每个视图选择图像。

此任务的指定方法是:

 -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
      UIImage *image;
        image = [info objectForKey:UIImagePickerControllerOriginalImage];
        [_imgView setImage:image];
        [self dismissViewControllerAnimated:YES completion:NULL];
}

但是如何通知此方法有关哪个按钮调用了图像选择器并分别选择/显示视图上的图像。

4

2 回答 2

2

添加一个“私有”(是的,我不知道这样的事情)ivar 来保存对 selectedImageView 的引用

@interface MyViewController ()

@property (nonatomic, strong) UIImageView *selectedImageView;

@end

Then when the imageView is selected use this new ivar to keep a reference to the currently active imageView

- (void)imageViewTapped:(id)sender
{
  // This assumes the use of a gesture recognizer but you can substitute your usual method
  // of detecting the imageView that you want to edit.
  self.selectedImageView = [sender view];
}

现在你的代表看起来像这样

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  self.selectedImageView.image = info[UIImagePickerControllerOriginalImage];
  self.selectedImageView = nil;

  [self dismissViewControllerAnimated:YES completion:nil];
}
于 2013-04-03T08:26:51.423 回答
0

在类级别上,获取一个包含 imageview 引用的变量。

当您点击图像时,将点击的图像视图的引用存储到此变量中。

进入 imagepicker 委托方法,使用这个变量来设置图像。

于 2013-04-03T08:16:11.863 回答