1

ASINetworkQueue のインスタンスがあり、ASIHTTPRequest のインスタンスをキューに追加しました。その間、キューと各リクエストにデリゲート メソッドを設定しました。

[submittingReportQueue setDelegate:self];
[submittingReportQueue setRequestDidFailSelector:@selector(submitReportQueueWentWrong:)];
[submittingReportQueue setQueueDidFinishSelector:@selector(submitReportQueueFinished:)];

ループ内でリクエストをキューに追加し、ループの外側に呼び出し [submittingReportQueue go] を追加しました。

ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
 NSString *auth = [[AuthenticationManager sharedInstance] authenticationHeaderValue];
 request addRequestHeader:@"Authorization" value:auth];
 [request addRequestHeader:@"Content-Type" value:@"application/json"];
 NSString *jsonString =[self jsonStringForExpenseReport:report];
 [request appendPostData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
 [request setDelegate:self];
 [request setUserInfo:[NSDictionary dictionaryWithObject:report forKey:@"Report"]];
 [request setDidFailSelector:@selector(submitReportRequestWentWrong:)];
 [request setDidReceiveDataSelector:@selector(submitReportRequestDone:)];
 [requests addObject:request];
 [submittingReportQueue addOperation:request];

以下は私のデリゲートメソッドです:

- (void)submitReportQueueWentWrong:(ASINetworkQueue *)queue
{
    NSLog(@"Submit Report WentWRong");

//
- (void)submitReportQueueFinished:(ASINetworkQueue *)queue
{
    NSLog(@"Submit Report QueueFinished");

}
//
- (void)submitReportRequestWentWrong:(ASIHTTPRequest *)request
{
        NSLog(@"Submit Report Queue went wrong");
}

//
- (void)submitReportRequestDone:(ASIHTTPRequest *)request

{//do work here}

ただし、ASIHTTPRequest.m は次のコード ブロックで例外をスローします。

// Does the delegate want to handle the data manually?
if ([[self delegate] respondsToSelector:[self didReceiveDataSelector]]) {
  NSMethodSignature *signature = [[[self delegate] class]     
           instanceMethodSignatureForSelector:[self didReceiveDataSelector]];
  NSInvocation *invocation = [[NSInvocation invocationWithMethodSignature:signature] 
           retain];
 [invocation setSelector:[self didReceiveDataSelector]];
 [invocation setArgument:&self atIndex:2];
 NSData *data = [NSData dataWithBytes:buffer length:bytesRead];
 [invocation setArgument:&data atIndex:3];
 [invocation retainArguments];
 [self performSelectorOnMainThread:@selector(invocateDelegate:) withObject:invocation waitUntilDone:[NSThread isMainThread]];

[呼び出し setArgument:&data atIndex:3]; 例外をスローします。エラー メッセージは 'NSInvalidArgumentException' です。理由: '*** -[NSInvocation setArgument:atIndex:]: index (3) out of bounds [-1, 2]'

私は何を間違えましたか?

ありがとう `

4

1 に答える 1