gpt4 book ai didi

ios - 尽管图像远程存在于服务器上,但 SDWebImage 不显示图像

转载 作者:可可西里 更新时间:2023-11-01 03:49:10 24 4
gpt4 key购买 nike

我正在开发一个 iOS 应用程序,我正在使用 SDWebImage 作为图像下载器 API。

我正在使用 UICollectionView 并在方法中执行此操作

- (UICollectionViewCell *)collectionView:(SMToplinksCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

有些图片已下载,有些未下载。没有下载的显示错误信息:

2014-06-15 12:11:50.203 c_shadow_ios_iphone[6867:60b] ===Error:Error Domain=NSURLErrorDomain Code=-1100 "The operation couldn’t be completed. (NSURLErrorDomain error -1100.)"

错误 -1100:NSURLErrorFileDoesNotExist

此外,UIImage 似乎为零。

我已经检查了 SDWebImage 尝试下载的 URL,它正确地为我提供了图像,所以错误似乎不合理

这是我使用的方法代码:

- (UICollectionViewCell *)collectionView:(SMToplinksCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
SMToplinkCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:TopLinksCollectionViewID forIndexPath:indexPath];

NSArray *collectionViewArray = [self getToplinksArrayAccordingToTheIndex:collectionView.index];

// CONFIGURE THE CELL
SMTopLinksObject *dataObject = collectionViewArray[indexPath.item];

// 1. Set the toplink title
cell.title = dataObject.name;

// 2. Get the default image and blur it
cell.imageName = dataObject.localImageName;

// 3. Activate the preloader that shows the loading status

// 4. Load the image from the server
SDWebImageManager *manager = [SDWebImageManager sharedManager];
NSString *toplinksGetRequest = dataObject.prepareToplinksGetRequest;
NSURL *toplinksURL = [NSURL URLWithString:toplinksGetRequest];

NSLog(@"=== Trying to download image from URL:%@", toplinksGetRequest);
[manager downloadWithURL:toplinksURL
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize){
//progression tracking code
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished){
if(finished)
{
NSLog(@"===image finished loading, image:%@", image);
NSLog(@"===Error:%@", error);
}
if (image)
{ cell.shadowPageImageView.image = image; }
}];
NSLog(@"=========Cell:%@", cell);
return cell;
}

输出

image is NIL

Error: Error Domain=NSURLErrorDomain Code=-1100 "The operation couldn’t be completed. (NSURLErrorDomain error -1100.)"

我在这里错过了什么?

最佳答案

[cell.diviceIV sd_setImageWithURL:[NSURL URLWithString:imgStringUrl] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (image){
// Set your image over here
}else{
//something went wrong
}

}];

要点是您需要在方法中提供的 options:SDWebImageRetryFailed 选项。它对我有用,您可以尝试一下。

关于ios - 尽管图像远程存在于服务器上,但 SDWebImage 不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24228348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com