Iphone SDWebImage始终从URL加载占位符图像,而不是图像
嗯,使用SDWeb镜像 这些是我的代码:Iphone SDWebImage始终从URL加载占位符图像,而不是图像,iphone,objective-c,ios,uiimageview,sdwebimage,Iphone,Objective C,Ios,Uiimageview,Sdwebimage,嗯,使用SDWeb镜像 这些是我的代码: UIImageView *sellerImage = [[UIImageView alloc]init]; [sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:productPicture]] placeholderImage:[UIImage imageNamed:
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加载图像,但不会更改占位符图像
这是我问题的一个屏幕
尝试以下方法
UIImageView *sellerImage = [[UIImageView alloc]init];
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:
[productPicture stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[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");
}];
也可以尝试以下方法
UIImageView *sellerImage = [[UIImageView alloc]init];
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:
[productPicture stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[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");
}];
正确分配占位符图像。。我的问题是错误的图像扩展彼此不匹配,即占位符.jpeg和palceholder@2x.jpg使用未声明的标识符调度\u get\u main\u队列已修复。你可以再次检查。检查此链接。