Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMeek D
3,457 Pointsusing tag with actionsheet
basically i am trying to use tag with actionsheet because i am using two UIImages in the same view but each time i tried to save two differents images .Any Ideas Andrew Chalkley Amit Bijlani
2 Answers
Amit Bijlani
Treehouse Guest TeacherCan you post your code? I am not sure what are trying to do what is going wrong.
Meek D
3,457 PointsAmit Bijlani Basically what i am trying to do is that : first when the app is running the user will double tap on both UIImages then save it to parse then load it in the app and if the person choose to change the picture the same process will keep repeatting . BUT I AM HAVING TROUBLE TO SAVE TWO DIFFERENTS PICTURES SO I WAS TRYING TO USE ENUMS
Amit Bijlani
Treehouse Guest TeacherI don't think you need two tap gesture recognizers if you are assigning the final image to both UIImageViews
. Although, I'm not sure if that solves your problem.
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[ _imageview addGestureRecognizer:tap];
_imageview.userInteractionEnabled=YES;
[_imageview2 addGestureRecognizer:tap];
_imageview2.userInteractionEnabled=YES;
}
- (void) imageTapped:(UIGestureRecognizer *)gestureRecognizer {
UIActionSheet*sheet=[[UIActionSheet alloc]initWithTitle:@"Where did you save those pictures!!" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Library",@"camera", nil];
[sheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imagepicker1=[[UIImagePickerController alloc]init];
imagepicker1.delegate=self;
imagepicker1.allowsEditing=NO;
// since you are only changing the source type you need not create two instances
if(buttonIndex==0)
{
imagepicker1.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
}
else if (buttonIndex==1)
{
imagepicker1.sourceType=UIImagePickerControllerSourceTypeCamera;
}
[self presentViewController:imagepicker1 animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage*orginalImage=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
_imageview.image=orginalImage;
// you can assign the same original image to the other image view you need not create another one
_imageview2.image=originalImage;
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
@end
Meek D
3,457 PointsAmit Bijlani i was trying to save two different images but with my previous code once i try to show a picture it kept showing the same picture on both UIImagePickerCOntroller
Meek D
3,457 PointsMeek D
3,457 Points