Reputation: 71
I have 4 UIButtons and 4 UIImgeViews and each button should change image of its UIImageView using UIImagePickerController. Button #1 should change imageview #1 and so on. all should be different. It works fine with just the first button and imageview but I'm not sure how to apply it for all 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];
}
I know this only sets a picture to the first imageView but how can I do it for all 4 ?
Upvotes: 3
Views: 193
Reputation: 6806
The button-pressed code can leave a value lying around to say which button is being dealt with:
- (void) buttonPressed:(id)sender {
imageViewBeingEdited = sender.imageView;
// display image picker here
}
then
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
imageViewBeingEdited.image = [info objectForKey:UIImagePickerControllerOriginalImage];
...
}
Upvotes: 1