2012-02-29 6 views
1

次のAPIを使用してスレッドで何らかのアクションを実行したいので、奇妙なセレクタpoiOneBoxSearchが呼び出されていません。なぜですか?コードの間違い?ありがとう。不思議なことに、サブスレッドのIPhone performSelectorが機能しません。

- (void)poiOneBoxSearch{ 
    [self poiOneBoxSearcWithQueryString:@"coffee" isFinished:YES]; 
} 

- (void)test1{ 
    NSThread* thread = [[NSThread alloc] init]; 
    [self performSelector:@selector(poiOneBoxSearch) 
       onThread:thread 
      withObject:nil 
      waitUntilDone:YES]; 
    [thread release]; 
} 

答えて

2

あなたがリンク 下に読むべきですperformSelectorメソッドを使用したい場合、私はあなたがコードの下に使用していない場合はあなたが何か

Please Goes Through This Link

を逃したと考えてください。

この

- (void)test1{ 
[NSThread detachNewThreadSelector:@selector(poiOneBoxSearch) toTarget:self withObject:nil]; 
} 
+0

はい、この方法が機能します。 – jianhua

+0

これは、多くの他のオプションがバックグラウンドスレッドから呼び出されたときに機能しました。 –

0

はこれを試してみてください試してみてください:

[self performSelectorInBackground:@selector(poiOneBoxSearch) withObject:nil waitUntilDone:YES]; 
0
[self performSelectorInBackground:@selector(poiOneBoxSearch) withObject:nil]; 

- (void) poiOneBoxSearch{ 
      @autoreleasepool { 
    [self poiOneBoxSearcWithQueryString:@"coffee" isFinished:YES]; 
} } 

あなたが心に留めておく必要があり、最も重要なことは、このメソッドは指定されたセレクタにスレッドを作成するので、セレクタは、参照カウントされたメモリ環境内の他のスレッドと同様に、自動解放プールを持たなければなりません。

関連する問題