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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:43:10+00:00 2026-05-17T06:43:10+00:00

so here is the problem i have, i created two NSTimer objects and they

  • 0

so here is the problem i have, i created two NSTimer objects and they are fired when i button is pressed. then the user has 20 seconds to press another button which forces an alert to popup where they enter a validation code, and when they press the confirm button on the alert it is supposed to stop the timer. what is happening is that everything works until they press confirm but instead of the timer stopping it hangs for a second( which im thinking is a delay caused by the keyboard dismiss animation) and then the timer continues. any help would be greatly appreciated and here is all relevant code:

#import "hackergameViewController.h"
#import <AudioToolbox/AudioToolbox.h>


@implementation hackergameViewController

@synthesize decryptLabel, crackLabel, decryptButton, crackButton, submit, numberToDecrypt, numberToCrack, stopDecryptButton, stopCrackButton, inputCode;
@synthesize soundFileURLRefBeep;
@synthesize soundFileURLRefBuzz;
@synthesize soundFileObjectBeep;
@synthesize soundFileObjectBuzz;


NSTimer *decryptTimer;
NSTimer *crackTimer;
int crackTime;
int decryptTime;
NSString *codeToConfirm;

#pragma mark UIAlertView
- (void)confirm:(UIAlertView *)confirm clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex == 0){
        [confirm dismissWithClickedButtonIndex:0 animated:YES];
    }
    else {
            if (inputCode.text == codeToConfirm) {
            [self stopCrack];
            [self stopDecrypt];
        }
    }
}

-(void) generateDecryptionCode{
    codeToConfirm = [NSString stringWithFormat:@"%i%i%i%i%i%i", arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10];
    numberToDecrypt.text = codeToConfirm;
}

-(void) generateCrackCode{
    codeToConfirm = [NSString stringWithFormat:@"%i%i%i%i%i%i%i%i%i%i", arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10];
    numberToCrack.text = codeToConfirm;
}

- (void)dealloc {
    [decryptLabel release];
    [decryptButton release];
    [crackLabel release];
    [crackButton release];
    [submit release];
    [numberToCrack release];
    [numberToDecrypt release];
    [super dealloc];
}

- (void) confirmCode{
    UIAlertView *confirm = [[UIAlertView alloc] initWithTitle:@"Confirm Code" message:@"Please Input The Correct Code:"  delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm Code", nil];
    inputCode = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
    CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60);
    [confirm setTransform:myTransform];
    [inputCode setBackgroundColor:[UIColor whiteColor]];
    [confirm addSubview:inputCode];
    [confirm show];
    [confirm release];
    [inputCode release];

}


- (void) decryptTimerFires{

    if(decryptTime > 0){
        decryptTime--;
        decryptLabel.text = [NSString stringWithFormat:@"%g",    (float)decryptTime/10];
        if(decryptTime%10 == 0){
            AudioServicesPlaySystemSound (self.soundFileObjectBeep);
        }

    }
    else{
        [decryptTimer release];
        decryptTimer = nil;
    }
}
- (void) crackTimerFires{

    if(crackTime > 0){

        crackTime--;
        crackLabel.text = [NSString stringWithFormat:@"%g", (float)crackTime/10];
        if(crackTime%10 == 0){
            AudioServicesPlaySystemSound (self.soundFileObjectBeep);
        }
        else if(crackTime == 0){
            AudioServicesPlaySystemSound (self.soundFileObjectBuzz);
        }
    }
    else{
        [crackTimer release];
        crackTimer = nil;
    }
}

-(void) stopDecrypt{
    [decryptTimer invalidate];
    [decryptTimer release];
    decryptTimer = nil;
}
-(void) stopCrack{
    [crackTimer invalidate];
    [crackTimer release];
    crackTimer = nil;
}

-(IBAction)decrypt{
    [self generateDecryptionCode];
    decryptTime = 200;
    decryptTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(decryptTimerFires) userInfo:nil repeats:YES];
    [decryptTimer fire];

}

-(IBAction)crack{
    [self generateCrackCode];
    crackTime = 200;
    crackTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(crackTimerFires) userInfo:nil repeats:YES];
    [crackTimer fire];

}
  • 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-17T06:43:10+00:00Added an answer on May 17, 2026 at 6:43 am

    In your confirm method, are you sure that your inputCode.text == codeToConfirm is returning true? Have you tried using [inputCode.text compare:codeToConfirm]? From what I can see, your timers only get invalidated in stopCrack and stopDecrypt, which only get called if that comparison succeeds.

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

Sidebar

Related Questions

Here is my problem. I have created a pretty heavy readonly class making many
I have created a jsfiddle of my problem. Here is a link to the
Here is the problem: I have two columns in a table that, for each
I have problem about django template-db query relationship. For example, I created two tables
I have created two test accounts(buyer and seller) in PayPal sandbox. And then trying
Here's my situation: I have 2 person objects, person1 and person2, which were created
I'm having a problem with mixing managed and unmanaged code. I have created two
I have problem in below code. I have created two methods ENCRYPT and DECRYPT
Here's my problem: I have do create a menu/list of actions (which would be
I have problem adding arraylist to list view, will explain about my problem here..

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.