【问题标题】:Set images to the cells used NSArray from urls, but it doesn't work将图像设置为从 urls 使用 NSArray 的单元格,但它不起作用
【发布时间】:2014-05-16 04:18:58
【问题描述】:

我尝试创建一个简单的照片浏览器,并且我使用了 UICollectionView,当我尝试将拇指图像插入单元格时,它不起作用,它有一个线程,但我无法修复它,拜托帮帮我,非常非常感谢。这是我的代码:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView   cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ImageCell";
ImageCell *cell = (ImageCell *)[collectionView     dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

NSArray *images =    @[@"http://www.example.com/p1.jpg",@"http://www.example.com/p2.jpg",@"http://www.example.com/p3.jpg",@"http://www.example.com/p4.jpg"];
cell.imageView.image = [UIImage imageNamed:images[indexPath.row]];

return cell;
}

【问题讨论】:

    标签: ios image url nsarray collectionview


    【解决方案1】:

    您也可以使用 SDWEBIMAGE。因此你可以使用

    [cell.imageView setImageWithURL:[NSURL URLWithString:@"Your image url"]
                       placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    

    see this link.

    【讨论】:

    • 如果它对您有帮助,请为其他人点赞 :) 干杯
    • 顺便说一句,如果我想添加一个图片链接数组,我应该怎么做,我需要在拇指单元格中插入许多 url 图片,
    • 您可以将图像设置为 UIIMAGE 并使用该 UIIMAGE 填充您的数组。然后将其提供给您的单元格的 ImageView。
    • 我不明白该怎么做,你能不能告诉我,请帮帮我。
    • 将您的 url 数量放入任何数组中。然后 [cell.imageView setImageWithURL:[NSURL URLWithString:[Yourarray objectatIndex:IndexPath.Row]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 2017-08-10
    • 1970-01-01
    相关资源
    最近更新 更多