2011-06-24 8 views
-2

私はiPhoneのタイマー - 秒を待つ方法?

for (int i = 0; i < 3; i++) { 
    // something A 
    ... 

    // wating 
    [NSTimer scheduledTimerWithTimeInterval:10 
            target:self 
            selector:@selector(endTimer:) 
            userInfo:nil 
            repeats:YES]; 

    // something B 

    ... 
} 


- (void)endTimer:(NSTimer *)timer { 
    NSLog(@"end timer"); 
    [timer invalidate]; 
} 

Iのたい ' - >待機 - > B' ..秒を待つようにしようとしている

が、待っていないが...

A - > Bを - > A - > B - > A - > B - >終了タイマ、終了タイマ、終了タイマ

どうすればよいですか?

良い日

+0

あなたが私に気に入らなければ、あなたが求めていることを理解するのは難しいです。 – chewy

+0

すみません。私は英語を話さない...私は英語を勉強している。 – jPlus

+1

あなたは「回答を受け入れる」という意味を理解していますか? – chewy

答えて

1

を呼び出したい、そこからメイン機能でタイマーを作成、今

-(void)callA{ 
    //Do your thing... 
} 
-(void)callB{ 
    //Do your thing... 
} 
-(void)callFunction{ 
    count++; 
    if(count<3){ 
    [self performSelector:@select(callA) withObject:nil]; 
    [NSThread sleepForTimeInterval:3.0]; 
    [self callB]; 
    } 
    else{ 
     [timer invalidate]; 
    } 
} 

、これを試してみてください上記の機能。

+0

ありがとうJhaliya! – jPlus

0

あなたの質問をうまく言葉で表現されていない場合でも、

// set myCount somewhere as an INT with value 0 
// int myCount = 0; 

-(void)callA 
{ 
    if (myCount < 3){ 
     [self performSelector:@selector(callB) withObject:nil afterDelay:1.0]; 
    } 
} 


-(void)callB 
{ 
    myCount +=1; 
    [self performSelector:@selector(callA) withObject:nil afterDelay:1.0]; 

} 
+0

ありがとうShiShi !! – jPlus

関連する問題