gpt4 book ai didi

ios - 如何通过正确的请求删除关联的 UIProgressview?

转载 作者:行者123 更新时间:2023-11-29 11:21:43 24 4
gpt4 key购买 nike

我使用 asihttprequest 下载多个文件,我想知道如何在下载完成后通过正确的请求删除关联的 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];


}

问题是即使 contentArray 中有 3 个下载并且第二个先完成,此代码也会删除最后一个进度 View 。你能帮我吗?

最佳答案

如果您需要删除与已完成请求关联的进度 View ,您可以从请求的 downloadProgressDelegate 属性中获取它:

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

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

关于ios - 如何通过正确的请求删除关联的 UIProgressview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6755634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com