てぃーだブログ › やまの生態@東京ー>広島 › 電算術 › 【iOS】NSTimerの使い方

2011年06月14日

【iOS】NSTimerの使い方

iOSのSDKには、処理を待たすウェイトのような関数はないのかな?ということで、タイマーにて実現してみた。
startTimerを呼び出すと、3秒後にtickを呼び出すようにするには、


NSTimer *aTimer;

-(void)startTimer
{
if (aTimer) {
[self stopTimer];
}
aTimer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(tick:) userInfo:nil repeats:YES];
}
-(void)stopTimer
{
if (aTimer) {
[aTimer invalidate];
aTimer = nil;
}
}
-(void)tick:(NSTimer*)theTimer
{
if (aTimer) {
[self stopTimer];
}
//実際のタイマーイベントロジック
}


同じカテゴリー(電算術)の記事
Try WiMAX
Try WiMAX(2013-03-15 20:00)


Posted by やま104 at 08:36│Comments(0)電算術
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。