2012-05-11 3 views
2

なぜappDidFinishLaunchingに配置するとこれが繰り返されませんか?NSTimerがAppDelegateから繰り返さない

self.ti = [NSTimer timerWithTimeInterval:10. target:self selector:@selector(bounce:) userInfo:nil repeats:YES]; 
[self.ti fire]; 

多くのおかげ

ジュール

+0

を役に立てば幸い?また、あなたはどのように 'ティ'を設定していますか? – Jeremy1026

+0

はバウンスしています。私は単に、それが呼び出されているかどうかを見るために瞬間的にロギングしています。ティは私のヘッダ(強く非原子的)の中のプロパティであり合成されています。一度だけ繰り返すのではなく、コードは一度も発射されませんか?再び多くのおかげです – Jules

答えて

4

は、私はあなたのbounceが間違った署名を持っていると思います。それはあなたがこの方法をスケジュールするselector(bounce:)を使用する必要があります

- (void)bounce:(NSTimer*)theTimer { 
    NSLog(@"Here..."); 
} 

でなければなりません。またtimerWithTimeIntervalの代わりにscheduledTimerWithTimeIntervalを呼び出すする必要があります。それが役立つ場合

self.ti = [NSTimer 
    scheduledTimerWithTimeInterval:10. 
          target:self 
          selector:@selector(bounce:) 
          userInfo:nil 
          repeats:YES]; 
+0

あなたは正しかった、私は必要:私のセレクタで、ありがとう:) – Jules

4

私はわからないんだけど、scheduledTimerWithTimeInterval方法を使用してみてください。例:

self.ti = [NSTimer scheduledTimerWithTimeInterval:10. target:self selector:@selector(bounce) userInfo:nil repeats:YES]; 

は 'バウンス' 内のコードは何ですか、それは

+0

これも、感謝:) – Jules

関連する問題