在uitableview上显示customcell上imageview的进度

时间:2012-03-06 07:56:03

标签: ios uitableview uiactivityindicatorview custom-cell

我按照这里的代码https://stackoverflow.com/a/7212943/711837让我开始显示我的应用尝试从特定网站下载图片的指示器。场景是:

我有一个包含许多自定义单元格的tableview,自定义单元格有2个标签和一个imageview。 我有一个NSURL来下载将填充标签的内容,然后是一个单独的类,它将下载要填充到UIImageView的图像。微调器的代码和图像的下载是:

resultArray = [[NSArray alloc] initWithArray:response];
[self downloadImageFromInternet:@"http://static.colourlovers.com/images/shapes/0/7/7090/50x50.png"];
//spinner for the download
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 24, 24);
custcell.accessoryView = spinner;
[spinner startAnimating];
///[spinner release];

[self.thetableView reloadData];

然后我在课程的完成下载方法中调用[spinner stopAnimating]但不知何故,旋转器只是没有动画,或出现在这个问题上!我错过了什么吗?或者在某处我可以参考?我的目的是在UIIndicatorView的位置显示UIImageView,然后在加载后,imageview将占据相同的位置,这是在每个单元格上。

UPDATED添加了方法

-(void) downloadImageFromInternet:(NSString*)urlToImage{
    // Create a instance of InternetImage
    asynchImage = [[DownloadThumb alloc] initWithUrl:urlToImage];

    // Start downloading the image with self as delegate receiver
    [asynchImage downloadImage:self];
}

-(void) internetImageReady:(DownloadThumb*)downloadedImage{ 
    // The image has been downloaded. Put the image into the UIImageView
    [arrayImg addObject:downloadedImage.Image];
    [spinner stopAnimating];
    [self.thetableView reloadData];
}

-(void)downloadImage:(id)delegate{
m_Delegate = delegate;

NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:ImageUrl] 
                                              cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0];
imageConnection = [[NSURLConnection alloc] initWithRequest:imageRequest delegate:self];

if(imageConnection)
{
    workInProgress = YES;
    m_ImageRequestData = [[NSMutableData data] retain];
}

}

1 个答案:

答案 0 :(得分:0)

创建单元格时,您应该真正启动微调器 然后,您应该检查cellForRowAtIndexPath是否应该可见 最后,当您需要显示它时,您可以使用[tableView reloadData]来显示或删除它。