【发布时间】:2016-02-17 11:20:52
【问题描述】:
我有一组图像 URL,我想在 UITableView 的单独单元格上显示每个 URL 的图像。在我之前使用的代码中:
UIImageView *view_Image = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, 400, 180)];
view_Image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arrURL[i]]]];
这是在一个 for 循环中,因此 x、y 和 i 的值会随每个 UIImageView 发生变化。但是,当我在cellForRowAtIndexPath 中使用它时,这种方法不起作用。图片未显示,我对cellForRowAtIndexPath 的实现如下:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *simpleIdentifier = @"simpleIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleIdentifier];
}
cell.textLabel.text = _arrNames[indexPath.row];
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 300, 150)];
imv.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arr[i]]]];
[cell.contentView addSubview:imv];
return cell;
}
另外,当我直接添加图像的 URL 时,图像会显示在每一行中,但滚动会滞后很多。任何帮助将不胜感激。谢谢。
【问题讨论】:
-
您可以使用 SDWebImage 库。
-
使用下面的链接这将对您有所帮助。 stackoverflow.com/a/35455366/5934436
-
这可能会帮助你...MJTableImageSwift
标签: ios objective-c uitableview