我已经创建了自定义 tableView
并在其他类中使用自定义 tableView
类来显示 tableView
..
我正在从服务器加载图像并将其显示在 tableViewRow
中..每个 image
都不同..
在屏幕上,10 张图像中只有 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];
}
试试这个你的问题就会解决。
关于ios - 如何在 UITableView 中的图像中添加事件指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15331079/