- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
SDWebImageOptions 参数说明
我们使用的时候,一般就是用第3点。实例如:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"app"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } // 取出模型 HMApp *app = self.apps[indexPath.row]; // 设置基本信息 cell.textLabel.text = app.name; cell.detailTextLabel.text = app.download; // 下载图片 NSURL *url = [NSURL URLWithString:app.icon]; UIImage *placeholder = [UIImage imageNamed:@"placeholder"]; SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageLowPriority; [cell.imageView sd_setImageWithURL:url placeholderImage:placeholder options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) { // 这个block可能会被调用多次 NSLog(@"下载进度:%f", (double)receivedSize / expectedSize); } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { NSLog(@"----图片加载完毕---%@", image); }]; return cell; }
/** * 当app接收到内存警告 */ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { SDWebImageManager *mgr = [SDWebImageManager sharedManager]; // 1.取消正在下载的操作 [mgr cancelAll]; // 2.清除内存缓存 [mgr.imageCache clearMemory]; }
原文:http://www.cnblogs.com/jys509/p/4847542.html