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

  • SEARCH
  • Home
  • 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 7007915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:40:08+00:00 2026-05-27T21:40:08+00:00

I have a working code from a tutorial but don’t understand it completely. Situation:

  • 0

I have a working code from a tutorial but don’t understand it completely.

Situation:

After a button was pressed in my iPhone App
an AlertView appears with three buttons.
Now I like to check what button the user pressed.

CODE FROM THE TUTORIAL:

- (IBAction)infoButtonPressed:(id)sender {

    UIAlertView *myAlert1 = [[UIAlertView alloc]initWithTitle:@"My Alert View 1" 
                                                   message:@"Here we go" 
                                                  delegate:self 
                                         cancelButtonTitle:@"Cancel" 
                                         otherButtonTitles:@"Option1", @"Option2", nil];

    [alert show];
}





- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"Button: %i, was pressed.", buttonIndex);
}

Code works, I see the correct output in the console as a NSLog but how is it possible
that the method:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"Button: %i, was pressed.", buttonIndex);
}

refers to the correct alert view. In this case: myAlert1.

What about with more than one alert view.
For example a second one calling myAlert2.

I know the following code is not correct but it would make more sense to me
if I’d write the method as follow:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"Button: %i, was pressed.", buttonIndex_FROM_myAlert1);
}

Hope you can help, drives me nuts.

Regards,
Marc

  • 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-05-27T21:40:09+00:00Added an answer on May 27, 2026 at 9:40 pm

    how is it possible that the method refers to the correct alert view?

    For exactly that reason, the delegate method alertView:didDismissWithButtonIndex: actually tells you which alert view it refers to. Note that the method has two arguments. The second one tells you the button index and the first one points to the alert view this button index refers to.

    If you have more than one alert view that share the same delegate, you will have to check against the first argument which alert view this is about. To be able to do that, you would have to store the alert views in an ivar/property or other data structure in order to remember them in the delegate method. (Or, since UIAlertView is a subclass of UIView, you could use the tag property to distinguish between multiple views).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some reading from this tutorial , I have the following partly working code:
I have a working code (programmed by a tutorial) but like to dive in
I'm new to Django but I seem to have nearly identical code working on
Im working on the notepad tutorial from the android website. I have created a
I don't code in PHP, but I have this form which I pulled off
So I'm trying to get some tutorial code working, and I'm stuck. I have
do you have a working code to share. I’m trying to figure out how
As a beginner in Ocaml, I have this current working code: ... let ch_in
I have this code working in C#: var request = (HttpWebRequest)WebRequest.Create(https://x.com/service); request.Method = GET;
I have started working on some code left behind by previous developers, and I'm

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.