2011-02-06 23 views
0

iPhoneの場合、メソッド1の実行が完了した後、メソッド2を呼び出すことはできますか。メソッド1終了後の呼び出し方法2

+0

メソッド2を非同期に呼び出すことを意味しますか? – Max

+0

はい、方法1の実行が終了した後のみです。 – testndtv

+0

あなたの特定の事件についての詳細な背景を教えてください。 @meronixはうまく動作するオペレーションキューを提案しましたが、Observerや単純なデリゲートパターンのような単純なものが本当に必要であることを賭けています。 – Goles

答えて

4

あなたはそれがすべて非同期の方法あなたで作業が必要な場合は非同期に、私は

[self method1]; 
[self method2]; // will be called just when method1 has ended 

...カウスでない場合は... はあなただけ最初にmethod1にして、方法2を呼び出す必要があります」...と思いますが、 NSOperationQueueオブジェクトを見ることができます 多くのメソッドを追加することができるキューです。実行され、別の場所でコードに進むことができます... 2つ以上のメソッドを追加すると、それらは通常togheter(while )、オブジェクトを一度に1つだけ実行するように指示することができます。

NSOperationQueue *aQueue; 
aQueue = [NSOperationQueue new]; 
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self 
      selector:@selector(method1) object:nil]; 
[aQueue addOperation:operation]; 
[operation release]; 

[aQueue setMaxConcurrentOperationCount:1]; //tell aQueue to execute just 1 operation at a time 

operation = [[NSInvocationOperation alloc] initWithTarget:self 
      selector:@selector(method2) object:nil]; 
[aQueue addOperation:operation]; 
[operation release]; 

luca

関連する問題