【问题标题】:SDWebImage always load the placeholder image not the image from URLSDWebImage 始终加载占位符图像而不是来自 URL 的图像
【发布时间】:2012-11-17 21:38:09
【问题描述】:

嗯,使用 SDWeb 图像Here

这些是我的代码:

        UIImageView *sellerImage = [[UIImageView alloc]init];            
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:productPicture]]
                        placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

但它总是只加载占位符图像而不是来自 URL 的图像, 我尝试使用块来确保它是否加载图像并进入成功块,这意味着 SDWebImage 可以从 URL 加载图像但它不会更改占位符图像。

这些是我尝试使用块时的代码:

            [sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:productPicture]]
                placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                         success:^(UIImage *image, BOOL cached) 
        {
            NSLog(@"success Block");
        }
                         failure:^(NSError *error) 
        {
            NSLog(@"failure Block");
        }];

正如我所说,它总是进入成功块,这意味着它可以从 URL 加载图像,但不会更改占位符图像。

这是我的问题的一个屏幕。

【问题讨论】:

  • 查看此链接。 stackoverflow.com/questions/15701556/…>

标签: iphone objective-c ios uiimageview sdwebimage


【解决方案1】:

也可以试试下面的

[sellerImage setImageWithURL:[NSURL URLWithString:[productPicture stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
                placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                         success:^(UIImage *image, BOOL cached) 
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                sellerImage.image = image;
            });
            NSLog(@"success Block");
        }
                         failure:^(NSError *error) 
        {
            NSLog(@"failure Block");
        }];

【讨论】:

  • 使用未声明的标识符 dispatch_get_main_queue
  • 已修复。你可以再检查一遍。
【解决方案2】:

试试下面的

UIImageView *sellerImage = [[UIImageView alloc]init];            
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:
[productPicture stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

【讨论】:

    【解决方案3】:

    正确分配占位符图像。我的问题是错误的图像扩展名彼此不匹配,即 placeholder.jpeg 和 palceholder@2x.jpg

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-03
      • 2017-07-12
      相关资源
      最近更新 更多