objective c - How to run NSTimer until flag variable ON in Cocoa -
i have problem: want nstimer waiting until flag variable yes, if flag = yes, mytimer stop. how can that? tried below code:
nstimer *mytimer; int delay = 6.0; scantimer= [nstimer scheduledtimerwithtimeinterval:6.0 target:self selector:@selector(anotherfunc) userinfo:nil repeats:yes]; mytimer= [nstimer timerwithtimeinterval: delay target:self selector: @selector(resetall:) userinfo:nil repeats:no]; [[nsrunloop currentrunloop] addtimer:mytimer formode:nsmodalpanelrunloopmode]; [[nsapplication sharedapplication] runmodalforwindow: scanningpanel];
this resetall () function :
-(void) resetall: (nstimer *) thetimer { if(flag) { nslog(@"killwindow"); [[nsapplication sharedapplication] abortmodal]; [scanningpanel orderout: nil]; flag = no; } else { delay +=6.0; mytimer= [nstimer timerwithtimeinterval: delay target:self selector: @selector(resetall:) userinfo:nil repeats:no]; [[nsrunloop currentrunloop] addtimer:mytimer formode:nsmodalpanelrunloopmode]; [[nsapplication sharedapplication] runmodalforwindow: scanningpanel]; } }
i used 2 nstimer, mytimer run, scantimer not run. please give me suggestions. in advance
try this:- nstimer *mytimer; int delay = 6.0; scantimer= [nstimer scheduledtimerwithtimeinterval:6.0 target:self selector:@selector(anotherfunc) userinfo:nil repeats:yes]; mytimer= [nstimer scheduledtimerwithtimeinterval: delay target:self selector: @selector(resetall:) userinfo:nil repeats:no]; [nsapp beginsheet:scanningpanel modalforwindow:[self window] modaldelegate:self didendselector:nil contextinfo:self]; - (void)resetall:(nstimer *)thetimer { if (flag== yes) { [nsapp endsheet:scanningpanel]; [scanningpanel orderout:self]; flag=no; } else { delay +=6.0; mytimer= [nstimer scheduledtimerwithtimeinterval: delay target:self selector: @selector(resetall:) userinfo:nil repeats:no]; [nsapp beginsheet:scanningpanel modalforwindow:[self window] modaldelegate:self didendselector:nil contextinfo:self]; } }
Comments
Post a Comment