2

こんにちは私はNSTimerを使用してカウントダウンを作成し、ラベルを使用してこれを表示しようとしています。問題は、ラベルが2つ下がって、理由がわからないことです。何か案は?

ここに私のコードがあります

   - (void)viewDidLoad
   {
       NSLog(@"%@", self.chosenTime);
       [self startGame];
       [super viewDidLoad];

       NSString *timeString =  self.chosenTime;
       self.timer = [timeString intValue];
       self.countdown.text = timeString;
       // Do any additional setup after loading the view.
    }

    - (void)startGame
    {
        [self introCountdown];
        [self performSelector:@selector(goAnimation) withObject:nil afterDelay:3.0];
        NSString *timeString =  self.chosenTime;
        self.timer = [timeString intValue];
        [self performSelector:@selector(startCountdown) withObject:nil afterDelay:4.0];
    }

    - (void)startCountdown
    {
         //self.countdownTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(decrementTimer:) userInfo:nil repeats:YES];
         self.countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.00 target:self selector:@selector(decrementTimer:) userInfo:nil repeats:YES];
    }

    - (void)decrementTimer:(NSTimer *)timer
    {
       if(self.timer > 0)
       {
           self.timer = self.timer - 1;
           self.countdown.text = [NSString stringWithFormat:@"%d", self.timer];
       }
       else 
       {
            [self.countdownTimer invalidate];
            self.countdownTimer = nil;
        }
    }
4

2 に答える 2

0

このコードは正しいようです。ラベルのテキストを別の場所から変更している可能性がありますか?

于 2012-05-02T10:54:10.897 に答える
-1

誤解して申し訳ありません。コードは正しいです。UI の問題または別の場所からのラベルの処理のようです。可能であればソースを xib に添付してください

于 2012-05-02T10:51:30.700 に答える