scheduledTimerWithTimeInterval:invocation:repeats:
タイマーを作って返します
+(NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds: invocation:(NSInvocation *)invocation: repeats:(BOOL)repeats:
解説
タイマーを作って返します。
secondsで指定した時間(秒)が過ぎた後、ターゲットに起動のメッセージを送ります。
タイマーの時間(second)が0.0以下にセットされた場合は最小の正の数のセットされます。
repeatsをYESにすると、タイマーは繰り返して実行されます。NOをセットすると1回だけメッセージを送ります。
返り値
( NSTimer * )
タイマーオブジェクト
引数
( NSTimeInterval )seconds
タイマーの長さ(秒)0.0以下にセットされた場合は最小の正の数のセットされます
( NSInvocation * )invocation
起動オブジェクト
( BOOL )repeats
繰り返すかどうかYES/NO
フレームワーク
Foundation
クラス
NSTimer
Class Methods
使用可能
10.0
参照
例文
#import "MyObject.h" @implementation MyObject NSTimer *timer=nil; - (IBAction)myAction:(id)sender { //メソッドシグネチャ NSMethodSignature* aSignature ; //起動オブジェクト NSInvocation *invocation ; //セレクタ SEL aSelector = @selector( timerControl ); //メソッドシグネチャ aSignature = [ self methodSignatureForSelector:aSelector ]; //起動オブジェクトを作る invocation = [ NSInvocation invocationWithMethodSignature:aSignature ]; //ターゲットをセット [ invocation setTarget: self ]; //セレクタをセット [ invocation setSelector: aSelector ]; //タイマースタート timer = [NSTimer scheduledTimerWithTimeInterval:1.0 invocation:invocation repeats:YES]; } -(void) timerControl{ NSLog(@"..."); } @end