ASIHTTP: multi threads and multi UIPorgressView
Posted
by user262325
on Stack Overflow
See other posts from Stack Overflow
or by user262325
Published on 2010-03-12T08:06:25Z
Indexed on
2010/03/12
8:07 UTC
Read the original article
Hit count: 597
iphone
Hello everyone
I have a project to download multi files (fileurl). It display the each thread on a UITableView. In UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ NSInteger row=[indexPath row];
NSInteger section=[indexPath section];
//UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"any-cell"];
static NSString *SimpleTableIdentifier1 = @"SimpleTableIdentifier1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier1];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: SimpleTableIdentifier1] autorelease];
}
UIProgressView *aUIProgressView;
aUIProgressView =[[UIProgressView alloc] initWithFrame:CGRectMake( 10.9f,48.0f,300.0f,28.0f)];
[aUIProgressView setTag:row];
[aUIProgressView setProgress:0];
[cell addSubview:aUIProgressView];
[self startADownloadThread : [[downloadArray objectAtIndex:row] getURL] progressview:switchView ];
[aUIProgressView release];
[cell setText: [[downloadArray objectAtIndex:row] getURL]];
return cell;
}
It calls 'startADownloadThread'
- (IBAction)startADownloadThread:(NSString *)fileurl
progressview:(UIProgressView *)a
{
[a setProgress:0];
NSLog(@"Value: %f", [a progress]);
[networkQueue cancelAllOperations];
[networkQueue setDownloadProgressDelegate:a];
[networkQueue setDelegate:self];
[networkQueue setRequestDidFinishSelector:@selector(requestDone:)];
[networkQueue setShowAccurateProgress:true];
NSURL *url = [NSURL URLWithString:fileurl];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[networkQueue addOperation:request];
[networkQueue go];
}
I hope each aUIProgressView display the download progress of each download thread.
The above source codes :
Display the aUIProgressView list correctly, but only the last aUIProgressView link to a thread display the correct progress, others' value are 0
Welcome any comment
Thanks
interdev
© Stack Overflow or respective owner