我正在倒計時計時器,並且無法在計數小於0時使if語句停止定時器。解決此問題的任何指導將會很大讚賞。在此先感謝您的幫助..NSTimer - 如果語句不在定時器內工作 - CountDown定時器
-(void) startCountdown{
time = 90;
//NSLog[@"Time Left %d Seconds", time];
//This timer will call the function updateInterface every 1 second
myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateInterface:) userInfo:nil repeats:YES];
}
-(void) updateInterface:(NSTimer*)theTimer{
if(time >= 0){
time --;
CountDownText.text = [NSString stringWithFormat:@"%d", time];
NSLog(@"Time Left %d Seconds", time);
}
else{
CountDownText.text [email protected]"Times Up!";
NSLog(@"Times Up!");
// Timer gets killed and no longer calls updateInterface
[myTimer invalidate];
}
}
問題是什麼?計時器是否繼續倒計時? – 2010-11-13 20:41:11