使用UIProgressView自定义UITableViewCell

时间:2011-09-17 09:45:09

标签: ios uitableview asihttprequest

我正在使用ASIHTTPRequest下载文件。我的自定义UITableViewCell包含UIProgressView,其UIPRogressView的属性名为downloadProgressView。 当我推送下载的次数超过tableView可以显示在可见区域时,UIProgressView工作奇怪。当我开始滚动时,单元格中UIProgressView的值是混合的。 我异步下载文件。

以下是创建新下载的方法。

 -(void) pushDownload:(NSString *) url :(NSString *) fileName
{
    [downloads addObject:fileName];
    [downloadsTableView reloadData];

    NSURL *url = [NSURL URLWithString:url];
        //This is my custom cell
    DownloadCell *cell = (DownloadCell *)[downloadsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[downloads indexOfObject:fileName] inSection:0]];
    [cell.deleteDownloadButton setImage:[UIImage imageNamed:@"stop.png"] forState:UIControlStateNormal];
    __block ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
    [request setDownloadDestinationPath:@"somepath"];
    [request setDownloadProgressDelegate:cell.dowloadProgressView];
    cell.currentRequest = request;
    [request setShowAccurateProgress:YES];
    cell.status = Downloading;
    [request startAsynchronous];
}   

以下是创建新单元格的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
 (NSIndexPath *)indexPath 
  {
static NSString *CellIdentifier = @"myCell";
DownloadCell *cell = (DownloadCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
    NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"DownloadCell" owner:nil options:nil];

    for (id nibObject in nibs) {
        if ([nibObject isKindOfClass:[DownloadCell class]]) {
            cell = nibObject;

        }
    }
    [cell.deleteDownloadButton setImage:[UIImage imageNamed:@"symbol_stop.png"] forState:UIControlStateNormal];

}

cell.textLabel.text = [audioDownloads objectAtIndex:indexPath.row];
if (cell.status==Downloaded) {
   cell.dowloadProgressView.progress==1.0;
}

return cell;
}

当我开始滚动时,为什么进度视图值会混合?即使下载完成的值有时仍在混合。

0 个答案:

没有答案