2013-06-20 4 views
6

私は、scheduleTimerWithTimeIntervalを使用して、一定の時間、定期的な作業を行いたいとします。しかし、私のコードにどのように実装するのですか?ここに私のコードです:ios scheduledTimerWithTimeInterval時間の長さ

timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 
              target: self 
             selector: @selector(doSomething:) 
             userInfo: nil 
             repeats: YES]; 
+1

あなたのコードは正常に見えます。 'doSomething:'メソッドをブレークポイントし、呼び出されているかどうかを確認します。 –

答えて

5

1分とします。ここで

は単純なシナリオ、あらゆる秒間呼び出され

timer = [NSTimer scheduledTimerWithTimeInterval:1 target:(self) selector:@selector(countDown) userInfo:nil repeats:YES]; 
remainingCounts = 60; // int remainingCounts ;... 

方法です。

-(void)countDown { 
NSLog(@"%d", remainingCounts); 
    // Do Your stuff...... 
    if (--remainingCounts == 0) { 
    //[self dismissViewControllerAnimated:YES completion:nil]; 
    [timer invalidate]; 
} 

}

関連する問題