SDWebImageManager 图像未加载到 TableViewController [英] SDWebImageManager image not loaded into TableViewController

查看:27
本文介绍了SDWebImageManager 图像未加载到 TableViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SDWebImageImagemanger 来处理异步调用和缓存.但是它不会将图像返回到 cell.imageview.view.代码如下:

I am using SDWebImageImagemanger to hadnle asyn call and caching. However it does not return the image to the cell.imageview.view. Here is the code:

        NSString *imageURLString=[[tableData objectAtIndex:indexPath.row] valueForKey:@"picture"];
        NSURL *url = [NSURL URLWithString:imageURLString];
        SDWebImageManager *manager = [SDWebImageManager sharedManager];
        [manager downloadWithURL:url
                         options:0
                        progress:^(NSInteger receivedSize, NSInteger expectedSize)
         {
             // progression tracking code
         }
                       completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
         {
             if (image)
             {
                 cell.imageView.image = image;
             }
         }];

推荐答案

你应该这样使用它:

NSString* imageURL = [[tableData objectAtIndex:indexPath.row] valueForKey:@"picture"];
[cell.imageView setImageWithURL:[NSURL URLWithString:imageURL]];

为此,首先导入类别:

#import <SDWebImage/UIImageView+WebCache.h>

请注意,您根本没有使用管理器,您只是使用了库提供的UIImageView+WebCache 类别,它为您提供了setImageWithURL: 方法.该方法还有其他变体,可让您跟踪下载过程、完成处理程序等.

Please note that you don't use the manager at all, you just use the UIImageView+WebCache category provided by the library, which gives you the setImageWithURL: method. There are other variants of the method which allows you to keep track of the download process, a completion handler, etc.

这篇关于SDWebImageManager 图像未加载到 TableViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆