iphone - NSTimer not invalidating or is refiring -


so here problem have, created 2 nstimer objects , fired when button pressed. user has 20 seconds press button forces alert popup enter validation code, , when press confirm button on alert supposed stop timer. happening works until press confirm instead of timer stopping hangs second( im thinking delay caused keyboard dismiss animation) , timer continues. appreciated , here 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 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];  } 

in confirm method, sure inputcode.text == codetoconfirm returning true? have tried using [inputcode.text compare:codetoconfirm]? can see, timers invalidated in stopcrack , stopdecrypt, called if comparison succeeds.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -