我正在开发一个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似乎为nil。
我已经检查了SDWebImage尝试下载的URL,并成功获取了图像,因此错误似乎不合理。
以下是我使用的方法代码:
- (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似乎为nil。
我已经检查了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;
}
输出
图像为NIL
错误:错误域=NSURLErrorDomain Code=-1100“操作无法完成。(NSURLErrorDomain error -1100.)”
我错过了什么?