我想下载使用asinetworkqueue的网址列表,它下载得很好。但是当我滚动uitableview时,我的uiprogressview隐藏起来。UIProgressView滚动uitableview时隐藏
我的意思是如果进度显示在第2行,如果我滚动它,然后隐藏进度视图。然后完成第2行的下载后,它显示第3行的进度视图。
总之,当滚动uitableview时,活动uiprogressview被隐藏。
请帮我解决这个问题。
非常感谢您的时间..
Upadated-实际问题:当下载未完成行(例如行1号),现在如果我滚动tableview中,看到了一行没有1,即使尚未完成下载,progressview也会隐藏。一旦第1行的下载完成,它开始对第2行进行降低编码,现在显示进度视图。
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.jpg"]];
CGRect tblViewFrame = CGRectMake(7 , 0 , self.view.bounds.size.width - 14, self.view.bounds.size.height - 90);
self.tblViewDownload = [[[UITableView alloc]initWithFrame:tblViewFrame style:UITableViewStyleGrouped]autorelease];
self.tblViewDownload.backgroundColor = [UIColor clearColor];
self.tblViewDownload.showsVerticalScrollIndicator = FALSE;
self.tblViewDownload.scrollEnabled = YES;
self.tblViewDownload.delegate = self;
self.tblViewDownload.dataSource = self;
[self.view addSubview:self.tblViewDownload];
index = 0;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[self loadArray];
}); // Do any additional setup after loading the view.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.myUrlArray count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:
(NSIndexPath *)indexPath
{
CGFloat rowHeight = 75.0;
return rowHeight;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d", indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *lblTitle, *lblAuthor;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero]autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
lblTitle = [[[UILabel alloc]initWithFrame:CGRectMake(65, 10, 220, 25)]autorelease];
lblTitle.backgroundColor = [UIColor clearColor];
//lblTitle.font = [UIFont boldSystemFontOfSize:15.0];
lblTitle.font = [UIFont fontWithName:@"Palatino-Bold" size:15.0];
lblTitle.text = @"Sample title";
[cell.contentView addSubview:lblTitle];
lblAuthor = [[[UILabel alloc]initWithFrame:CGRectMake(65, 30, 220, 25)]autorelease];
lblAuthor.backgroundColor = [UIColor clearColor];
lblAuthor.font = [UIFont italicSystemFontOfSize:13.0];
lblAuthor.textColor = [UIColor grayColor];
lblAuthor.text = @"sample authior";
[cell.contentView addSubview:lblAuthor];
}
return cell;
}
-(void)loadArray{
NSString *urk = @"http://sample/iphone/video/video_2.mov";
self.myUrlArray = [[NSMutableArray alloc]init];
for(int i = 0;i<10;i++){
[self.myUrlArray addObject:urk];
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[self downLoadPoems];
});
}
-(void)downLoadPoems{
if(index < [myUrlArray count])
{
NSLog(@"this is the index %d",index);
NSIndexPath *myIP = [NSIndexPath indexPathForRow:index 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];
if(index < [myUrlArray count])
{
NSString *url = [myUrlArray objectAtIndex:index];
NSArray *aPoemArrayUrls = [NSArray arrayWithObjects:url,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];
}
}
-(void)queueCompleted:(ASINetworkQueue*)queue{
NSLog(@"queueCompleted");
self.tblViewDownload.userInteractionEnabled = YES;
UIProgressView *progressv = (UIProgressView*)queue.downloadProgressDelegate;
if (progressv)
[progressv removeFromSuperview];
if (index < [myUrlArray count]){
index++;
[self downLoadPoems];
}
}
- (void)requestDone:(ASIHTTPRequest *)request
{
NSLog(@"request done");
NSString *response = [request responseString];
}
- (void)requestWentWrong:(ASIHTTPRequest *)request
{
NSLog(@"request went wrong");
NSError *error = [request error];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
你需要澄清这个问题 - 我(也可能是其他人)不理解问题。第0行有一个表格。第1行有一个进度条,并且表示“下载xxx进度”直到完成,然后切换为显示下一个项目的进度。您的表格中还有其他物品,但它们与前两项无关。当用户滚动表格以查看其他项目时,进度栏将被隐藏。即使在表中有一个单元格,并且您让用户滚动表格,您也希望进度条魔术般地保持可见状态。你能看到我的困惑吗? – 2012-08-10 12:52:45
@DavidH:首先感谢您花时间做出回应。我的问题是当第一行开始下载时,progressview被显示出来。这很好。问题是当我在滚动uitableview的时候出现downaloding尚未完成行1号,现在当我再次看到第1行时,它不可见,即使它没有完成下载。我看不到在该行中的进度。在完成行号1的下降后,它将显示进度查看第2行是这个问题,请帮助 – user198725878 2012-08-10 13:30:50