私はこの問題に悩まされています。マルチスレッドの問題のように見えますが、この種のトピックにはまったく慣れていません。専門家からの助けが必要です!!!
【問題の状況】
3 つの引数を持つメソッドを呼び出す必要があり、1 つの引数は
@selector( myMethod: )
(1) を複数回呼び出す必要がある
次のステップに進むには、(1) の各セレクターが完了していることを確認する必要があります
@selector( myMethod: )
簡単にするためにオブジェクトXの配列であるxArrayを設定していますしたがって、論理的には、マルチスレッドがアクセスするxArrayが1つあり、何らかの方法でxArrayのすべての要素を処理する必要があります...
【感想】
私が置く必要があるのは @selector 引数を持つメソッドであるため、 performSelector は役に立ちません...
【疑似コード】
// The Starting Point of Alghorithm
- (void)initialCallerMethod {
for(int i=0; i < [calendarArray count]; i++) {
calendar = [calendarArray objectAtIndex:i];
// fetch the events feed
NSString* alternateLink = [calendar alternateLink];
NSURL* feedURL = [NSURL URLWithString:alternateLink];
if (feedURL) {
[self setEventFeed:nil];
GDataQueryCalendar *query = [GDataQueryCalendar calendarQueryWithFeedURL:feedURL];
[query setMaxResults:100];
GDataServiceGoogleCalendar *service = [[[CalendarService alloc] init] calendarService];
GDataServiceTicket *ticket;
ticket = [service fetchFeedWithQuery:query
delegate:self
didFinishSelector:@selector(calendarEventsTicket:finishedWithFeed:error:)];
if ([self eventFetchError] == nil) {
// query succeeded
NSLog(@"Query succeeded");
[self howToDoThis];
}
}
}
}
// @selector's method with 3 arguments
- (void)calendarEventsTicket:(GDataServiceTicket *)ticket
finishedWithFeed:(GDataFeedCalendarEvent *)feed
error:(NSError *)error {
[self setEventFeed:feed];
}
//
// Somewhere I want to do something like this
//
- (void) howToDoThis {
GDataFeedCalendarEvent* feed = [self eventFeed];
NSArray *entries = [feed entries];
// for now, I get's zero...
NSLog(@"FEED ENTRIES COUNT: %d", [entries count]);
for (int idx = 0; idx < [entries count]; idx++) {
// to make it simple, I'm just accumulating elements of array
id elm = [entries objectAtIndex:idx];
[anArrayToSumUp addObject: elm ];
}
}
本当に溢れてる…
ご意見をお聞かせください...
かつみ
==== 進歩か苦労か… 2009/10/29
ティム、私は NSInvocation と NSInvocationOperation を読みました。便利そうですね。さて、「セレクターのアドレス」の渡し方はわかりましたか?ご覧のとおり、NSInvocation でターゲット、セレクター、および引数を設定できますが、@selector(...) のアドレスを渡すにはどうすればよいですか?
[NSInvocation を使用する前に] ticket = [service fetchFeedWithQuery:query delegate:self didFinishSelector:@selector(calendarEventsTicket:finishedWithFeed:error:)];
【NSInvocationを使おうとして、セレクターを引数に渡す以外は近づきます】
retInvo = [NSInvocation invocationWithMethodSignature: [self methodSignatureForSelector:@selector(finishMethod:withArray:)]]; [retInvo setTarget:self];
// * これは問題です * [retInvo setSelector:@selector(finishMethod:withArray:)]; //これはOKではありません
[retInvo setArgument:&calendar atIndex:2]; [retInvo setArgument:&events atIndex:3];
NSInvocationOperation* invoFinishOperation = [[NSInvocationOperation alloc] initWithInvocation:retInvo];