我的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];
}
但是如何通知此方法有关哪个按钮调用了图像选择器并分别在视图上选择/显示图像。
答案 0 :(得分:2)
添加“私人”(是的,我知道没有这样的东西)ivar来保存对selectedImageView的引用
@interface MyViewController ()
@property (nonatomic, strong) UIImageView *selectedImageView;
@end
然后当选择imageView时,使用这个新的ivar来保持对当前活动的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];
}
答案 1 :(得分:0)
在类级别上,取一个包含imageview引用的变量。
当您点击图像时,将点击的图像视图的参考存储到此变量中。
进入imagepicker委托方法,使用此变量设置图像。