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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:01:34+00:00 2026-06-04T12:01:34+00:00

I need some help with my code. I have an UIAlert that pops up

  • 0

I need some help with my code.
I have an UIAlert that pops up the first time that you open the app, in that pop up I have two buttons and the user will choose one of those. I want the app to remember what button the user chose to execute some code or other. The thing is I have this code right here :

-(void)changeLabel{


        progressView.progress += 0.25;
    scan.hidden = YES;


        if (progressView.progress == 1 ) {
            label.hidden = YES;

            progressView.hidden = YES;

            [timer invalidate];

            imagesText.hidden = NO;


            int randomNumber = arc4random() % 4;

            switch (randomNumber) {
                case 0:


                    imagesText.image = [UIImage imageNamed:@"image1.png"];


                    break;

                case 1:


                    imagesText.image = [UIImage imageNamed:@"image2.png"];


                    break;

                case 2:

                    imagesText.image = [UIImage imageNamed:@"image3.png"];

                    break;
                case 3:

                    imagesText.image = [UIImage imageNamed:@"image4.png"];

                default:
                    break;

        }
    }
}

So I want to make it in some way that if the user selected the first button the app will do the switch between cases 0,1 and 2 and if he selected the second button it’ll do it between 3 and others. But I want the beginning of the code to be the same for both cases.
I tried some stuff but it doesn’t work how I wanted.
Thank you for your help!

UPDATE: I got the error fixed. So right now I have this :

- (void)viewDidLoad
{


    if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"alert"] ]) {
        [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"alert"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        UIAlertView *alerta = [[UIAlertView alloc]initWithTitle:@"Welcome!" message:@"Select your language" delegate:self cancelButtonTitle:@"Button1" otherButtonTitles:@"Button2", nil];



        [alerta show];
        [alerta release];

    }


    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];



   progressView.progress += 0.25;
    scan.hidden = YES;


    if (progressView.progress == 1 ) {
        label.hidden = YES;

        progressView.hidden = YES;

        [timer invalidate];

        imagesText.hidden = NO;

        int randomNumber;

        if ([buttonTitle isEqualToString:@"Button1"]) {

             randomNumber = arc4random() % 3;

        }else if ([buttonTitle isEqualToString:@"Button2"]) {

             randomNumber = arc4random() % 3 + 3;

        }

        switch (randomNumber) {
           //CODE
        }
    }
}

The problem is that all that code is supposed to be called from :

 - (IBAction)scan:(id)sender {

    label.hidden = NO;
    imagesText.hidden = YES;
    progressView.hidden = NO;


    progressView.progress = 0;

    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(alertView) userInfo:nil repeats:YES];

}

So I changed the @selector to the alertView one and now when I press the button that execute all the code it gives me that SIGABRT error. Any ideas why?
Thank you for all your help!

  • 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-04T12:01:35+00:00Added an answer on June 4, 2026 at 12:01 pm

    When the user chooses a button, you need to populate a property with some unique value of the button, like its title or a tag. Once you have that, you can put an if statement before your randomNumber definition — something like this:

    if (buttonTitle isEqualToString:@"First Button") {
            int randomNumber = arc4random() % 3; // Gives choices of 0,1, or 2
        }else if (buttonTitle isEqualToString:@"Second Button"){
            int randomNumber = arc4random() % 3 + 3; // Gives choices of 3,4, or 5
        }
    
         switch (randomNumber) .... (rest of your code)
    

    In the else-if statement the +3 will ensure that the choices in the switch statement will start with 3 and go up from there (I don’t know how many other choices you have).

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

Sidebar

Related Questions

Need some help joining these two tables I have two views that looks like
I need some help. I have an app that is based on UITabBarController. It
So, I need some code help. I've got an awkward little MySQL table that
I have one jQuery code and need some help from u guys to improve
I need some help - I have tried setting setSpecificDate so that the array
Need some help, I have a regular expression that appears to work just fine
i need some help. i have this code: <%= f.datetime_select :date, :start_year => 2011
need some help! I'm trying to write some code in objective-c that requires part-of-speech
I need some help with jQuery. I have a droplist that is selected retrieved
Hey guys! I need some help writing a code that creates an array in

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.