0

あなたの答えのおかげで、私は完全にうまく機能するNSタイマーのカウントダウンを持っています。ただし、タイマーは最後の 0s:99 ms をカウントしないように最後の 1 秒をスキップします。私のコードに何か問題がありますか? よろしくお願いします!

-(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

            [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) {
                timeLabel.text = @"0:00";
                [self performSelector:@selector(stopped) withObject:nil afterDelay:2.0];

            }
            else {[self setTimer]; }
        }
        else

            tmp.milisecondsCount = 99;
    }


    NSString *timerOutput = [NSString stringWithFormat:@"%2d:%2d", tmp.secondsCount, tmp.milisecondsCount];

    timeLabel.text = timerOutput;






}
4

2 に答える 2

0

これを変更してみてください

-(void) setTimer {
    MySingletonCenter *tmp = [MySingletonCenter sharedSingleton];
    tmp.milisecondsCount = 100;// Change this from 99 to 100
    tmp.secondsCount = 2;



    tmp.countdownTimerGame = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];


}
于 2013-09-27T19:56:45.703 に答える