如何将活动指标添加到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]; }
试试这个你的问题将解决。
- Xcode 6.4计划选项在El Capitan Beta中消失
- 如何在不设置“userID”的情况下注销nil
- 如果使用UISearchController重新加载数据,导航栏将消失
- UIScrollView在缩放或滚动时阻止所有触摸
- 更新GKTurnBasedMatch中的matchData而不结束转弯
- 如何清除存储在UIImage objective-c中的图像
- 如何实现@property(class,readonly,copy,nonatomic)NSArray * _Nullable readableTypeIdentifiersForItemProvider;
- Xcode 7如何刷新configuration文件?
- 如何在越狱的iOS设备上访问沙箱外的文件系统?