2010-08-17 70 views
1

我有一個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]'

什麼了我做錯了?

感謝 `

回答

1

的問題是在這裏:

[request setDidReceiveDataSelector:@selector(submitReportRequestDone:)]; 

這裏:

- (void)submitReportRequestDone:(ASIHTTPRequest *)request 


didReceiveDataSelector可能不是你想要的人,因爲它的每一次叫大量的數據被收到 - 我懷疑你想在請求完成時被調用,所以你d,而不是設置requestDidFinish選擇:

[request setRequestDidFinishSelector:@selector(submitReportRequestDone:)]; 


您的信息,你基本上看到的錯誤的意思是「你給了我選擇不具有正確的調用簽名」或更具體的「我試圖調用一個需要2個參數的方法,而你的方法只需要1個「。 (如果我沒有記錯,它在索引3上失敗的原因是第一個參數是包含該對象的隱藏參數。)

相關問題