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 7633321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:51:04+00:00 2026-05-31T06:51:04+00:00

I have a function that shows a UIAlertView with YES/NO buttons, and it is

  • 0

I have a function that shows a UIAlertView with YES/NO buttons, and it is used only inside the function’s scope so I dont want to implement a delegation to catch the user feedback.

Is there any way to know what button users clicked without implement UIAlertViewDelegate, something like:

[alert show];
if([alert indexOfClickedButton] == indexOfYes)
{
....
}

Or lambda expression as in Animation

  • 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-31T06:51:06+00:00Added an answer on May 31, 2026 at 6:51 am

    There is no way to avoid delegation completely, but you could create a wrapper to that effect along these lines:

    @interface MyAlertViewDelegate : NSObject<UIAlertViewDelegate>
    
    typedef void (^AlertViewCompletionBlock)(NSInteger buttonIndex);
    @property (strong,nonatomic) AlertViewCompletionBlock callback;
    
    + (void)showAlertView:(UIAlertView *)alertView withCallback:(AlertViewCompletionBlock)callback;
    
    @end
    
    
    @implementation MyAlertViewDelegate
    @synthesize callback;
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        callback(buttonIndex);
    }
    
    + (void)showAlertView:(UIAlertView *)alertView
             withCallback:(AlertViewCompletionBlock)callback {
        __block MyAlertViewDelegate *delegate = [[MyAlertViewDelegate alloc] init];
        alertView.delegate = delegate;
        delegate.callback = ^(NSInteger buttonIndex) {
            callback(buttonIndex);
            alertView.delegate = nil;
            delegate = nil;
        };
        [alertView show];
    }
    
    @end
    

    (ARC is assumed, if you are not using it change delegate = nil to [delegate release].)

    Usage would be something like:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm" message:@"Yes or No?" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes",@"No", nil];
    [MyAlertViewDelegate showAlertView:alert withCallback:^(NSInteger buttonIndex) {
        // code to take action depending on the value of buttonIndex
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a Facebook-like chat. I want to implement the function that shows/hides the
I have a jquery function that shows/hides spans that look like tips when I
I have a little function that shows latest activity, it grab timestamp in unix
I have a function that takes an element, and then shows all the other
I have this function that shows a list of messages in reverse order. protected
I have a simple function that shows and hides elements if a user clicks
I have a jQuery function that shows a 'loading' image and disable the submit
I have a UIAlertView that asks a user whether they want to copy a
I have a function that shows a map page so I can get the
I have a javasccript function that shows or hides spans when I click an

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.