我有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个图片设置?
答案 0 :(得分:1)
按下按钮的代码可以留下一个值来说明正在处理的按钮:
- (void) buttonPressed:(id)sender {
imageViewBeingEdited = sender.imageView;
// display image picker here
}
然后
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
imageViewBeingEdited.image = [info objectForKey:UIImagePickerControllerOriginalImage];
...
}