3

我有 4 个 UIButtons 和 4 个 UIImgeViews,每个按钮都应该使用 UIImagePickerController 更改其 UIImageView 的图像。按钮 #1 应该改变 imageview #1 等等。一切都应该不同。仅使用第一个按钮和 imageview 即可正常工作,但我不确定如何将其应用于所有 4 个按钮。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

UIImage *image1 = [info objectForKey:UIImagePickerControllerOriginalImage];


NSData *data = UIImagePNGRepresentation(image1);
NSString *myGrabbedImage = @"myGrabbedImage.png";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *fullPathToFile = [documentDirectory stringByAppendingPathComponent:myGrabbedImage];

[data writeToFile:fullPathToFile atomically:YES];
[[self firstImageView]setImage:image1];


[self dismissViewControllerAnimated:YES completion:nil];

}

我知道这只会将图片设置为第一个 imageView 但我怎样才能为所有 4 做呢?

4

1 回答 1

1

按下按钮的代码可以留下一个值来说明正在处理哪个按钮:

- (void) buttonPressed:(id)sender {
      imageViewBeingEdited = sender.imageView;
      // display image picker here
}

然后

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    imageViewBeingEdited.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    ...
}
于 2012-11-26T21:58:16.990 回答