我有一個ASINetworkQueue的實例,並且向隊列中添加了ASIHTTPRequest的實例;同時,我有委託方法的隊列以及每個請求設置:ASIHTTPRequest:嘗試調用我的委託方法時出錯
[submittingReportQueue setDelegate:self];
[submittingReportQueue setRequestDidFailSelector:@selector(submitReportQueueWentWrong:)];
[submittingReportQueue setQueueDidFinishSelector:@selector(submitReportQueueFinished:)];
和在一個循環我添加請求隊列中,添加通話[submittingReportQueue去]環的外側。
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:&數據atIndex:3 ]。拋出異常,錯誤 消息是 'NSInvalidArgumentException' 的,原因是: '*** - [NSInvocation的 setArgument:atIndex:]:索引(3)出界[-1,2]'
什麼了我做錯了?
感謝 `