2011-01-29 13 views
0

私の状況は次のとおりです。データを収集するための同期HTTPリクエストを作成していますが、手前にナビゲーションバーのタイトルビュー内にローディングビューを配置します。リクエストが終了したら、titleViewをnilに戻したいと思います。iPhoneナビゲーションバーのタイトルを表示同期要求の問題

[self showLoading];  //Create loading view and place in the titleView of the nav bar. 
[self makeHTTPconnection]; //Creates the synchronous request 
[self endLoading];   //returns the nav bar titleView back to nil. 

ローディングビューは、要求が終わった後に表示されるので、ローディングビューが表示されます。

私の問題:この時点では明らかですが、基本的に[self showLoading]が完了するまで [self makeHTTPconnection]の機能を延期したいと考えています。

ありがとうございました。

答えて

1

これを同期アプローチで実行することはできません。 あなたが[自己showLoading]メッセージを送信した場合、全体の方法が終了するまで、それはすでに、他の二つのタスク(endLoading makeHTTPConnectionを)終えるだろうので、UIは、更新されることはありません。その結果、読み込みビューは表示されません。このような状況のため

可能な解決策は、同時に作業することになります。

- (void)_sendRequest 
{ 
    [self makeHTTPConnection]; 
    //[self endLoading]; 
    [self performSelectorOnMainThread:@selector(endLoading) withObject:nil waitUntilDone:YES]; 
} 

[self showLoading]; 
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; 
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_sendRequest) object:nil]; 
[queue addOperation:operation]; 
[operation release]; 

次に、あなたがしなければならない* _sendRequest *メソッドを追加します

関連する問題