2011-11-07 3 views
1

たとえば、テキスト「text」のラベルがあり、5秒後に自動的に変更されます。 5秒間に何が起こるのですか? コードのサンプルをお願いします。タイマーのココア

答えて

3

NSTimerが必要です。 the documentationをチェックしてください。おそらくscheduledTimerWithTimeInterval:invocation:repeats:またはscheduledTimerWithTimeInterval:target:selector:userInfo:repeats:のいずれかが必要です。ここでは簡単な例です:

[NSTimer scheduledTimerWithTimeInterval:5 
           target:self 
           selector:@selector(updateString) 
           userInfo:nil 
           repeats:NO]; 

updateStringのようなものです: `繰り返した場合、あなたはそれで終了したときにタイマー` -invalidate`を送って、また

-(void)updateString 
{ 
    [textField setStringValue:@"new text"]; 
} 
+1

: '' YES'です。 – Justin

+0

ありがとうございます! –