2012-05-02 25 views
1

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

HERESに私のコード誤解のために申し訳ありません

- (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; 
     } 
    } 
+1

startCountDownを呼び出したコードを投稿できますか? – giorashc

+0

hmmm .. startCountDownを明示的に呼び出すことができますか([self startCountdown])、動作するかどうか確認してください。 – giorashc

+1

BTW [super viewDidLoad]はviewDidLoad()で最初に実行する必要があります – giorashc

答えて

-1

、コードが正しい、それはUIの問題またはどこか他の場所からラベルを扱うようで、このコードは思わ可能

+0

これはその質問に対する答えではありません。 –

+0

これは間違っています – giorashc

+0

これは動作しません2のカウントダウンがまだ1回だけ私はそれが欲しいので、ラベルは毎秒カウントダウン – iamlukeyb

0

場合XIBさんとあなたのソースを添付正しいこと。ラベルのテキストを別の場所から変更しているかもしれませんか?

+0

私は値を表示するためにアンロードし、その値からeery秒をカウントダウンするようにビューを変更しています – iamlukeyb

+0

あなたは 'startValue = 10;'を持っているとします。 10、9、...、0のようにラベルを付けるといいでしょう。タイマーはカウンターが減少した後にラベルのテキストを変更するので、値をインクリメントする必要があります(この場合、startValue = 11;)。 – demon9733