NSTimer - スケジュール実行

定期的に実行したり、時間を置いて実行する処理には、NSTimerを使います。

scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:

インスタンスを作るだけで実行が始まります。
引数

  • scheduledTimerWithTimeInterval
    実行間隔(秒)

  • target
    メッセージの送信先オブジェクト
  • selector
    メッセージの送信先セレクタ
  • userInfo
    NSTimerに持たせるユーザデータ
  • repeats
    繰り返しの有無 YES/NO

ソースコード例

selfのupdateClickメソッドを0.02秒間隔で実行します。

[NSTimer
     scheduledTimerWithTimeInterval:0.02f
     target:self
     selector:@selector(updateClock)
     userInfo:nil
     repeats:YES];

参考
NSTimer Class Reference

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">