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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:27:13+00:00 2026-05-31T07:27:13+00:00

I have a counter in my app that has a reset button, but instead

  • 0

I have a counter in my app that has a reset button, but instead of resetting immediately after tapped, I want a UIAlertView to popup and have the user tap Reset again as a button in the alert. I’m not entirely well experienced in this so I would ask that your answer just simply add/replace parts of my code below. I’m working on this lol. Thanks for any help!

- (IBAction)reset {
    UIAlertView *alert = [[UIAlertView alloc] 

                          initWithTitle:@"titleHere"
                          message:@"messageHere"
                          delegate: self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"Reset", nil];
    alert.tag = TAG_RESET;
    [alert show];
}

-(void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == TAG_DEV) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite.com"]]; // just another alert don't worry about this one
    } else if (alertView.tag == TAG_RESET) { // i need help here        
    }
}

So basically just an IBAction within an alert.

UPDATE:
How would I incorporate this to the button?

-(IBAction)zero {
    counter=0;
    count.text = [NSString stringWithFormat:@"%i",counter];
}

UPDATE2:

So I did this, which now clears the count perfectly, the only issue is now the alert continues to pop up after you tap either cancel or reset…

-(IBAction)resetButtonPushed {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"titleHere"
                                                    message:@"messageHere"
                                                   delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"Reset", nil];
    alert.tag = TAG_RESET;
    [alert show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == TAG_DEV){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite.com"]]; // just another alert don't worry about this one
    }
    else if (alertView.tag == TAG_RESET) { [self resetButtonPushed]; {
        counter=0;
        count.text = [NSString stringWithFormat:@"%i",counter];
    }        if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"Reset"]){
        // Reset button tapped
        }
    }
}
  • 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-31T07:27:15+00:00Added an answer on May 31, 2026 at 7:27 am

    I would advise against marking your zero function as IBAction when you’re looking over your code later it will be confusing.

    The naming of your reset method could also be confusing. I would suggest a more descriptive name. And also use of the standard IBAction method signature of taking in a sender parameter. Like so:

    -(IBAction)resetButtonPushed:(id)sender {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"titleHere"
                                                        message:@"messageHere"
                                                       delegate: self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Reset", nil];
        alert.tag = TAG_RESET;
        [alert show];
    }
    

    It would seem you are familiar with the UIAlertViewDelegate paradigm of waiting for a callback. Since you are using -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex you would use the clickedButtonAtIndex:(NSInteger)buttonIndex parameter passed into the delegate method. Like so:

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        if (alertView.tag == TAG_DEV){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite.com"]]; // just another alert don't worry about this one
        }
        else if (alertView.tag == TAG_RESET) {
            if (buttonIndex == alertView.cancelButtonIndex){
                // reset alert cancel button was tapped
            }
            else {
                // Reset button tapped
            }
        }
    }
    

    Alternatively you could do something like:

    if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"Reset"]){
        // Reset button tapped
    }
    

    This section in response to comment

    I’m not sure why you’re having difficulty understanding how to call your zero method. I assume it’s because the term IBAction is unnecessarily distracting you. IBAction is another way of saying void. The only difference is that when you use IBAction interface builder “sees” the method. As far as code is concerned the following two method definitions are identical.

    -(void)zero;
    -(IBAction)zero;
    

    Again I would also advise against the IBAction and for a more descriptive method name. Perhaps something like:

    -(void)zeroTheCounter {
        counter=0;
        count.text = [NSString stringWithFormat:@"%i",counter];
    }
    

    You would of course call this method just like any other, to use it in the context from the above example.

            else {
                // Reset button tapped
                [self zeroTheCounter];
            }
    

    Response to “edit 2” Of course it shows another alert view, you ask it to with the [self resetButtonPushed] call in the alertview delegate method.

    This edit uses the code currently in you question.

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        if (alertView.tag == TAG_DEV){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite.com"]]; // just another alert don't worry about this one
        }
        else if (alertView.tag == TAG_RESET) { 
            //[self resetButtonPushed]; { calling this will cause another alertview.
            //counter=0; this is done is zero
            //count.text = [NSString stringWithFormat:@"%i",counter]; this is done in zero
            //} 
            if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"Reset"]){
                // Reset button tapped
                [self zero];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that collects Perfmon counter values through the API exposed in
I have a simple django page that has a counter on it. I use
I have an app that has requirements for various hardware needs on the adroid
I have a multi-threaded Cocoa app that processes images. The program has a progress
I have a counter hash that I am trying to sort by count. The
I have a Silverlight app that uses actions to get data from the model
I have an app that holds a lot of pictures and when the user
I have a very dynamic web app that is dynamically created controls at run-time.
I have a .NET2.0 C# web-app. It has a variable number of large, init-expensive
In a Rails 3.2 app I have defined two methods that perform a calculation

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.