2011-07-20 16 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]; 
}