2012-08-08 2 views
0

아래 기능은 서버에서 콘텐츠를 다운로드하지 않고 ASIHTTPRequestErrorDomain Code = 4"요청을 취소했습니다.ASIHTTPRequestErrorDomain Code = 4 "요청이 취소되었습니다.

이 함수는 viewdidload에서 호출됩니다. 그러나 동일한 URL이 제대로 작동하고 - (void) downLoad : (id) 보낸 사람 이벤트 : (id) 이벤트 함수에서는 내용을 잘 다운로드하지만 - (void) startDownload 함수입니다. 아래의 기능이 아닌 미세

-(void)downLoad:(id)sender event:(id)event{ 

self.tblViewDownload.userInteractionEnabled = NO; 

IsRequestCompleted = NO; 

CGPoint touchPosition = [[[event allTouches] anyObject] locationInView:self.tblViewDownload]; 
NSIndexPath *indexPath = [self.tblViewDownload indexPathForRowAtPoint:touchPosition]; 
UITableViewCell *Cell = [self.tblViewDownload cellForRowAtIndexPath:indexPath]; 

progress = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar]; 
progress.frame = CGRectMake(65, 55, 210, 25); 
progress.progress = 0.0; 
[Cell.contentView addSubview:progress]; 

UIButton* button = (UIButton*)sender; 
button.hidden=YES; 

if(!self.networkQueue) 
    self.networkQueue = [[[ASINetworkQueue alloc] init] autorelease]; 

[self.networkQueue cancelAllOperations]; 
[self.networkQueue setQueueDidFinishSelector:@selector(queueCompleted:)]; 
[self.networkQueue setShowAccurateProgress:YES]; 
[self.networkQueue setDownloadProgressDelegate:progress]; 

[self.networkQueue setDelegate:self]; 

NSDictionary *aDict =[self.myUrlArray objectAtIndex:[indexPath row]]; 
NSString *aImgUrl = [aDict objectForKey:@"IMG_URL"]; 
NSString *aVideoUrl = [aDict objectForKey:@"VIDEO_URL"]; 
NSString *aAudioUrl = [aDict objectForKey:@"AUDIO_URL"]; 

NSArray *aPoemArrayUrls = [NSArray arrayWithObjects:aImgUrl,aVideoUrl,aAudioUrl,nil]; 

for(NSString* urlString in aPoemArrayUrls) 
{ 
    NSURL *url = [NSURL URLWithString:urlString]; 
    ASIHTTPRequest *downloadAFileRequest = [[ASIHTTPRequest requestWithURL:url]retain]; 
    NSString *Filename = [urlString lastPathComponent]; 
    NSLog(@"%@ filename",Filename); 
    [downloadAFileRequest setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]]; 
    [downloadAFileRequest setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:Filename]]; 
    [downloadAFileRequest setShouldContinueWhenAppEntersBackground:YES]; 
    [downloadAFileRequest setDelegate:self]; 
    [downloadAFileRequest setDidFinishSelector:@selector(requestDone:)]; 
    [downloadAFileRequest setDidFailSelector:@selector(requestWentWrong:)]; 
    [downloadAFileRequest setShowAccurateProgress:YES]; 

    [self.networkQueue addOperation:downloadAFileRequest]; 
    //---- 
} 

[self.networkQueue go]; 

} 

을하고있다 - ((무효) startDownload) 함수 아래

내 기능에 문제/잘못된 일이 무엇인지 알려주세요 ASIHTTPRequestErrorDomain Code = 4 "요청이 취소되었습니다.

-(void)startDownload{ 

if([self.myUrlArray count] > 0){ 

int count = [self.myUrlArray count]; 

int i = count - count; 

NSLog(@"%d iiiiii",i); 

NSIndexPath *myIP = [NSIndexPath indexPathForRow:i inSection:0]; 

UITableViewCell *Cell = [self.tblViewDownload cellForRowAtIndexPath:myIP]; 

progress = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar]; 
progress.frame = CGRectMake(65, 55, 210, 25); 
progress.progress = 0.0; 
progress.backgroundColor = [UIColor redColor]; 
[Cell.contentView addSubview:progress]; 

    if(!self.networkQueue) 
     self.networkQueue = [[[ASINetworkQueue alloc] init] autorelease]; 

    [self.networkQueue cancelAllOperations]; 
    [self.networkQueue setQueueDidFinishSelector:@selector(queueCompleted:)]; 
    [self.networkQueue setShowAccurateProgress:YES]; 
    [self.networkQueue setDownloadProgressDelegate:progress]; 

    [self.networkQueue setDelegate:self]; 

    NSDictionary *aDict =[self.myUrlArray objectAtIndex:[myIP row]]; 
    NSString *aImgUrl = [aDict objectForKey:@"IMG_URL"]; 
    NSString *aVideoUrl = [aDict objectForKey:@"VIDEO_URL"]; 
    NSString *aAudioUrl = [aDict objectForKey:@"AUDIO_URL"]; 

    NSArray *aPoemArrayUrls = [NSArray arrayWithObjects:aImgUrl,aVideoUrl,aAudioUrl,nil]; 

    for(NSString* urlString in aPoemArrayUrls) 
    { 
     NSURL *url = [NSURL URLWithString:urlString]; 
     ASIHTTPRequest *downloadAFileRequest = [[ASIHTTPRequest requestWithURL:url]retain]; 
     NSString *Filename = [urlString lastPathComponent]; 
     NSLog(@"%@ filename",Filename); 
     [downloadAFileRequest setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]]; 
     [downloadAFileRequest setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:Filename]]; 
     [downloadAFileRequest setShouldContinueWhenAppEntersBackground:YES]; 
     [downloadAFileRequest setDelegate:self]; 
     [downloadAFileRequest setDidFinishSelector:@selector(requestDone:)]; 
     [downloadAFileRequest setDidFailSelector:@selector(requestWentWrong:)]; 
     [downloadAFileRequest setShowAccurateProgress:YES]; 

     [self.networkQueue addOperation:downloadAFileRequest]; 
    } 

    [self.networkQueue go]; 


} 
} 

답변

2

두 번째 기능에 IsRequestCompleted = NO;을 설정하는 것을 잊었을 것 같습니다. 또한 cancelAllOperations를 보내는 이유는 무엇입니까? 그것은 큰 문제가 될 가능성이 있습니다.

또한 자동 실행을 사용하여 self.networkQueue을 다시 생성 할 필요가 없습니다. 수업에 한 번만 설정하고 -dealloc에 출시하십시오.

+1

셀에 직접 추가하는 나쁜 아이디어 [Cell.contentView addSubview : progress]; 재사용하면 논리가 깨질 것입니다. – NeverBe

+0

동의하지 않았습니까? –

관련 문제