Abo*_*tef 5 iphone objective-c uiimageview ios sdwebimage
嗯在这里使用SDWeb图像
这些我的代码:
UIImageView *sellerImage = [[UIImageView alloc]init];
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:productPicture]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
Run Code Online (Sandbox Code Playgroud)
但是它总是加载占位符图像而不是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");
}];
Run Code Online (Sandbox Code Playgroud)
正如我所说,它总是在成功阻止,这意味着它可以从URL加载图像,但它不会改变占位符图像.
这些是我的问题的屏幕.

还可以尝试以下方法
[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");
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8382 次 |
| 最近记录: |