2011-07-20 17 views
1

我使用asihttprequest下载多个文件,我想知道如何在下载完成后使用正确的请求删除关联的UIProgressview。如何使用正确的请求删除关联的UIProgressview?

NSMutableArray *contentArray包含ASIHTTPRequestNSMutableArray *progArray包含我的自定义UIProgressview。

-(void)addDownload:(NSString *)theURL withName:(NSString *)fileName 
{ 
theProgress = [[PDColoredProgressView alloc] initWithFrame:CGRectMake(3, 17, 314, 14)]; 
//... 
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:theURL]]; 
//.. 
[request setDelegate:self]; 
    [request setDownloadProgressDelegate:theProgress]; 
    request.allowResumeForFileDownloads = YES; 
    [request startAsynchronous]; 
    [request setShouldContinueWhenAppEntersBackground:YES]; 
    [contentArray addObject:request]; 
    [progArray addObject:theProgress]; 
    [theProgress retain]; 

    [self.tableView reloadData]; 
} 

- (void)requestFinished:(ASIHTTPRequest *)request{ 

     [contentArray removeObject:request]; 
     [progArray removeObject:theProgress]; 
     NSLog(@"%@",progArray); 
     NSLog(@"%@",contentArray); 
     [self reloadMyData]; 
     [self.tableView reloadData]; 


     } 

的问题是,这个代码删除最后一个progressview即使有3周下载量contentArray,第二个完成第一。 你能帮我吗?

回答

2

如果您需要删除与成品请求相关联的进步视图中,可以从要求的downloadProgressDelegate财产得到它:

- (void)requestFinished:(ASIHTTPRequest *)request{ 

    PDColoredProgressView *progress = (PDColoredProgressView*)request.downloadProgressDelegate; 
    [contentArray removeObject:request]; 
    if (progress) 
     [progArray removeObject:progress]; 
    [self reloadMyData]; 
    [self.tableView reloadData]; 
}