0

我的 UIImage 没有加载我使用 [NSData datawithContentsOfURL:] 指定的 URL,即使该 URL(看似)正确。

这是我的 configureCell: 方法:

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{
  NSString *url = [photoUrls objectAtIndex:indexPath.section]; 

  cell.imageView.image = [UIImage imagewithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];  
}

这是“photoUrls”数组中的内容(不包括项目符号):

(

)

4

2 回答 2

0

我不会在配置单元格中使用 [nsdata dataWithContentsOfURL:] ,因为它会阻止 UI。还有你拥有它的方式,它会一遍又一遍地重新下载所有图像。

以下链接将帮助您在不阻塞 UI 的情况下异步下载数据。

http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial

https://github.com/rs/SDWebImage

有了这个 SDWebImage,你所要做的就是: [cell.imageView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 它将负责下载图像。

于 2013-11-04T19:34:27.180 回答
0

您的网址未指向有效图片。我所看到的只是"Not found. Back to facebook"。您的调用[NSData dataWithContentsOfURL:]将获取数据,但[UIImage imageWithData:]无法生成 a UIImage,因为数据不代表有效图像。

于 2013-11-04T04:26:27.140 回答