초 및 밀리 초 : SS : MM으로 간단한 카운트 다운을하고 싶습니다. 그러나 타이머를 중지하거나 타이머가 0:00에 도달하면 작업을 수행하려고합니다. 현재 타이머가 작동하지만 0시에 멈 춥니 다. 초를 멈출 수는 있지만 밀리 초가되지는 않습니다. 뭐가 잘못 되었 니?NSTimer 밀리 초 카운트 다운
-(void) setTimer {
MySingletonCenter *tmp = [MySingletonCenter sharedSingleton];
tmp.milisecondsCount = 99;
tmp.secondsCount = 2;
tmp.countdownTimerGame = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];
}
-(void) timerRun {
MySingletonCenter *tmp = [MySingletonCenter sharedSingleton];
tmp.milisecondsCount = tmp.milisecondsCount - 1;
if(tmp.milisecondsCount == 0){
tmp.secondsCount -= 1;
if (tmp.secondsCount == 0){
//Stuff for when the timer reaches 0
//Also, are you sure you want to do [self setTimer] again
//before checking if there are any lives left?
[tmp.countdownTimerGame invalidate];
tmp.countdownTimerGame = nil;
tmp.lives = tmp.lives - 1;
NSString *newLivesOutput = [NSString stringWithFormat:@"%d", tmp.lives];
livesLabel.text = newLivesOutput;
if (tmp.lives == 0) {
[self performSelector:@selector(stopped) withObject:nil];
}
else {[self setTimer]; }
}
else
tmp.milisecondsCount = 99;
}
NSString *timerOutput = [NSString stringWithFormat:@"%2d:%2d", tmp.secondsCount, tmp.milisecondsCount];
timeLabel.text = timerOutput;
}
-(void) stopped {
NSLog(@"Stopped game");
timeLabel.text = @"0:00";
}
여기 좀 도와주세요 : http://stackoverflow.com/questions/15311289/nstimer-creating-a-timer-countdown – Woodstock
누가 이런 질문을 upvote 이해할 수 있습니까? – micantox