目前我正在将 SDWebImage 集成到我的项目中,
1)#import "UIButton+WebCache.h"
2)[button setImageWithURL:url placeholderImage:[UIImage imageNamed:@"no_photo.png"]];
现在我想知道图像何时下载成功,我怎么知道呢?
目前我正在将 SDWebImage 集成到我的项目中,
1)#import "UIButton+WebCache.h"
2)[button setImageWithURL:url placeholderImage:[UIImage imageNamed:@"no_photo.png"]];
现在我想知道图像何时下载成功,我怎么知道呢?
您可以使用以下setImageWithURL:
方法和块来执行此操作:
开始下载动画。然后使用它将图像下载到图像视图(或按钮,正如您在上面所做的那样)。
[imageView setImageWithURL:[NSURL URLWithString:imageURL]
placeholderImage:[UIImage imageNamed:@"YourPlaceholder.png"]
success:^(UIImage *image) {
// remove animation
}
failure:^(NSError *error) {
NSLog(@"thumbnail error: %@",error);
// handle failed download
}];
试试这个最新版本的 SDWebImageManager
/**
* Check if image has already been cached
*/
- (BOOL)diskImageExistsForURL:(NSURL *)url;
在项目中搜索memcache setObject
,该行将下载后的图像存储在缓存中。。在此行之后,您可以发布通知并在您自己的类中检查它。