皆さん。 私は非同期メソッドが "didFinish:@selector(SEL)"パラメータを持っている状況をどのように処理するのかを理解したいと思います。 私のコード例は次のとおりです。iPhoneアプリケーションで非同期メソッドを終了する方法をお勧めしますか?
//
// Authentication check
- (void)authenticationSuccess: (GDataServiceTicket*) ticket
authenticatedWithError: (NSError*) error {
if (error == nil)
{
NSLog(@"authentication success");
}
else
{
NSLog(@"authentication error");
}
}
//
- (void) fetchFeedOfSpreadsheets {
//create and authenticate to a google spreadsheet service
if (!(mService))
{
GDataServiceGoogleSpreadsheet *service = [self spreadsheetService];
[mService autorelease];
mService = [service retain];
}
// check autentication success (invoke "authenticationSuccess" method for debug success & error)
[mService authenticateWithDelegate: self
didAuthenticateSelector:@selector(authenticationSuccess:
authenticatedWithError:) ];
// HERE I WANT TO MAKE A PAUSE AND WHAIT THE RESULT, EITHER I AUTHENTICATED OR NOT
// AND MAKE AN "IF" STATEMENT TO CONTINTUE WORKING ON SERVER, OR RETURN ERROR
//fetch retrieves the feed of spreadsheets entries
NSURL *feedURL = [ NSURL URLWithString: kGDataGoogleSpreadsheetsPrivateFullFeed ];
GDataServiceTicket *ticket;
ticket = [mService fetchFeedWithURL: feedURL
delegate: self
didFinishSelector: @selector(spreadsheetsTicket:finishedWithFeed:
error:) ];
// HERE I WANT TO WAIT SECOND TIME. I WANT "spreadsheetsTicket:
// finishedWithFeed:error:" TO PROCCEED ERROR AND PUT A FEED IN SOME NSARRAY OBJECT
// AND AFTER THAT I WANT TO WORK WITH THAT NSARRAY RIGHT HERE
}
私は私が「authenticationSuccess」方法セクションの終わりに私が欲しいのコードをプッシュすることができ、明らかだが、それはそれはprobleを解決するために間違った方法だと、また明らかです。このようないくつかの状況があります。私はセレクタパラメータで非同期メソッドを呼び出し、柔軟なコードを書くソリューションを探したいと思っています。
ありがとうございます。
答えてくれてありがとう。 – zkaje
しかし、blocでgdata-objectivec-clientを変更することは、より困難な方法です。この抽象化されたロジックを作成します。/ ..so ..私は選択せず、 "didFinish:@selector"にコードを挿入しますか? – zkaje