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 trial

iOS

Trouble with buttons on UIAlertView iOS initWithTitle:message:delegate:

hey guys, I'm trying to work an If Else statement into my AlertView with little prevail. What I want is to have the AlertView dismissed when the user taps "cancel" so that my ImagePickerController is back how it was before the AlertView. And when the user taps "Leave" I would like the imagePickerConroller to dismiss and the camera/contents to reset and to have the user taken back to my homeViewController which is located at my TabBarController integer:1. Right now when I click on "cancel" or "leave" the alrtView is dismissed and my imagePickerController is displayed again but the "cancel" and "take Photo" button are disabled but still visible. I've tried plugging in many different methods/instances to try to accomplish this but haven't had any luck yet. There's got to be something that I am just not understanding or missing. please help! thanks!-

     -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Are you Sure?"
                                                    message:@"Leaving means you will not be able to return"
                                                   delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Leave", nil];
[alertView show];

}

 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex==1) {
}
else {
}

}

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

For the "Leave" scenario, what happens if you plug in [self.imagePicker dismissViewControllerAnimated:YES completion:nil]; inside the if block of your alertView:clickedButtonAtIndex method? (Or whatever your UIImagePickerController is named.)

For the "Cancel" scenario, I'm not sure how to cancel a cancel, so to speak. Since you are already in the imagePickerControllerDidCancel scenario, I'm not sure if you can abort the cancel. You might need to proceed with the cancel and just present the image picker a 2nd time. If you do it without animations you might be able to make it seamless. I'll be interested to hear what you end up getting to work.