如何将活动指标添加到UITableView中的图像?

我创build了自定义tableView并使用其他类中的自定义tableView类来显示tableView ..

我从服务器加载图像,并显示在tableViewRow ..每个image是不同的..

在屏幕上,只有7个图像会出现,当我向下滚动时,前3个图像重复一段时间,当这些图像加载显示正确的图像..但最初直到新的图像会显示旧图像,我想要放置一个活动指示器来显示图像正在加载而不是旧图像

我想在image的位置添加activity Indicator ,直到image加载..

我的代码是…

 self.tableViewX = tableView; static NSString *simpleTableIdentifier = @"SimpleTableCell"; SimpleTableCell *cell = (SimpleTableCell *)[tableView1 dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { NSString *imageURL = [NSString stringWithFormat: @"www.xyz.image.png"]; cell.thumbnailImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]]]; }); 

请帮助我一些示例代码

您可以使用“AsyncImageView”类文件,它将同步加载图像,并显示图像加载时的活动指标

您可以从以下链接下载“AsyncImageView”类文件: – https://www.dropbox.com/s/peazwjvky9fsjd7/Archive.zip

在.m文件中导入AsyncImageView类

  #import "AsyncImageView.h" 

在您的tableview单元格在indexpath方法

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"SimpleTableCell"; SimpleTableCell *cell = (SimpleTableCell *)[tableView1 dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } NSString *imageURL = [NSString stringWithFormat: @"www.xyz.image.png"]; AsyncImageView *async = [[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)]; [async loadImageFromURL:[NSURL URLWithString:imageURL]]; [cell.thumbnailImageView addSubview:async]; } 

试试这个你的问题将解决。