Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:32:06+00:00 2026-06-14T16:32:06+00:00

Im trying to do an app with 4 ImageViews and 4 UIButtons. When one

  • 0

Im trying to do an app with 4 ImageViews and 4 UIButtons. When one of the UIButtons are pressed a UIAlertView should appear with 3 options. One named “Picture” should open the photo library so the user can change the ImageView picture. I have wrote a code for this but it wont work. Do anyone have any suggestions on how to make it work?
Thanks in advance!

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
NSString *buttonOne = changeButtonOne;  //the UIButtons
NSString *buttonTwo = changeButtonTwo;
NSString *buttonThree = changeButtonThree;
NSString *buttonFour = changeButtonFour;


if([buttonOne isEqualToString:@"buttonOne"])
{
      if([title isEqualToString:@"Done"])
    {
        NSLog(@"You pressed done");
    }
      else if([title isEqualToString:@"Phone number"])
    {
        NSLog(@"You pressed Phone number");
    }
      else if([title isEqualToString:@"Picture"])
    {
        imagePickerController = [[UIImagePickerController alloc]init];   //I think its this part which are wrong
        [imagePickerController setDelegate:self];
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [self presentViewController:imagePickerController animated:YES completion:nil];
    }
}
else if([buttonTwo isEqualToString:@"buttonTwo"])
{
    if([title isEqualToString:@"Done"])
    {
        NSLog(@"Yoy pressed done");
    }
    else if([title isEqualToString:@"Phone number"])
    {
        NSLog(@"You pressed Phone number");
    }
    else if([title isEqualToString:@"Picture"])
    {
        imagePickerController2 = [[UIImagePickerController alloc]init];  //I think its the part thats wrong.
        [imagePickerController2 setDelegate:self];
        [imagePickerController2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [self presentViewController:imagePickerController2 animated:YES completion:nil];
    }

}
else if([buttonThree isEqualToString:@"buttonThree"])
    {
        if([title isEqualToString:@"Done"])
        {
            NSLog(@"You pressed done");
        }
        else if([title isEqualToString:@"Phone number"])
        {
            NSLog(@"You pressed Phone number");
        }
        else if([title isEqualToString:@"Picture"])
        {
            imagePickerController3 = [[UIImagePickerController alloc]init];   //i think this is the wrong part
            [imagePickerController3 setDelegate:self];
            [imagePickerController3 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            [self presentViewController:imagePickerController3 animated:YES completion:nil];
        }
    }

    else if([buttonFour isEqualToString:@"buttonFour"])
    {
        if([title isEqualToString:@"Done"])
        {
            NSLog(@"You pressed done");
        }
        else if([title isEqualToString:@"Phone number"])
        {
            NSLog(@"You pressed Phone number");
        }
        else if([title isEqualToString:@"Picture"])
        {
            imagePickerController4 = [[UIImagePickerController alloc]init];    //this is probably the wrong part
            [imagePickerController4 setDelegate:self];
            [imagePickerController4 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            [self presentViewController:imagePickerController4 animated:YES completion:nil];
        }
    }




}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:32:07+00:00Added an answer on June 14, 2026 at 4:32 pm

    You should use the tag property of UIAlertView to differentiate between the alerts and the buttonIndex (not the button title) to know which button was pressed.
    So don’t use isEqualToString at all in the alert view delegate method. You want this to work with different languages.

    In the button action, before you show the alert:

    alertView.tag = 1; // 1 = button1, 2 = button2 etc.
    

    Alert view delegate:

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (alertView.tag == 1) { //button1
            if (buttonIndex == alertView.cancelButtonIndex) {
                // handle cancel button
            }        
            if (buttonIndex == alertView.firstOtherButtonIndex) {
                // handle action 1
            }
            if (buttonIndex == alertView.firstOtherButtonIndex+1) {
                // handle action 2
            }
        }
        if (alertView.tag == 2) { //button2
            if (buttonIndex == alertView.cancelButtonIndex) {
                // handle cancel button
            }        
            if (buttonIndex == alertView.firstOtherButtonIndex) {
                // handle action 3
            }
            if (buttonIndex == alertView.firstOtherButtonIndex+1) {
                // handle action 4
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make an App with three options in a menu. One of
Trying to write app for service technicians that will display open service calls within
Trying to get MGTwitterEngine app to build. Getting one pesky error. The following ERROR.
I am trying to create an Activity for an Android app with two imageViews
I am trying to create an App that takes a picture when a button
im trying to make an app that has 4 ImageViews and I want to
I'm trying to get a basic image picker/photo taker running in my app and
I'm trying to take a photo from my iPhone app and upload to a
I'm currently trying to write an app for one special device running Android 2.3.4,
So I've been toiling over this app trying to figure out this strange behaviour

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.