网络多线程下载图片(SDWebImage)

#import "ViewController.h"

#import "XMGApp.h"


#import "UIImageView+WebCache.h"


@interface ViewController ()

/** tableView的数据源*/

@property(nonatomic ,strong) NSArray *apps;

/** 图片缓存*/

@property(nonatomic ,strong) NSMutableDictionary *images;

/** */

@property(nonatomic ,strong) NSOperationQueue *queue;


@property(nonatomic ,strong) NSMutableDictionary *operations;

@end


@implementation ViewController


#pragma mark -------------------

#pragma mark lazy Loading

-(NSArray *)apps

{

    if (_apps == nil) {

        NSArray *appsArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"apps.plist" ofType:nil]];

        

//        NSLog(@"%@",appsArray);

        NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:appsArray.count];

        //字典转模型  字典数组--->模型数组

        for (NSDictionary *dict in appsArray) {

            [arrayM addObject:[XMGApp appWithDict:dict]];

        }

        

        _apps = arrayM;

    }

    return _apps;

}


-(NSMutableDictionary *)images

{

    if (_images == nil) {

        _images = [NSMutableDictionary dictionary];

    }

    return _images;

}


-(NSOperationQueue *)queue

{

    if (_queue == nil) {

        _queue = [[NSOperationQueue alloc]init];

        _queue.maxConcurrentOperationCount = 5;

    }

    return _queue;

}


-(NSMutableDictionary *)operations

{

    if (_operations == nil) {

        _operations = [NSMutableDictionary dictionary];

    }

    return _operations;

}

#pragma mark -------------------

#pragma mark  UITableViewDataSource


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return self.apps.count;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    //1.创建cell

    static NSString *ID = @"app";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    

    //2.设置cell的数据

    //2.1 拿到这个cell对应的数据

    XMGApp *app = self.apps[indexPath.row];

    

    //2.2 设置文字

    cell.textLabel.text = app.name;

    cell.detailTextLabel.text = app.download;

    

    //2.3 设置图片

    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:[UIImage imageNamed:@"Snip20151124_183"]];

    

    //拿到沙盒的路径

    NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

    //文件名称

    NSString *fileName = [app.icon lastPathComponent];

    //拼接文件的全路径

    NSString *fullPath = [caches stringByAppendingPathComponent:fileName];

    

    NSLog(@"%@",fullPath);


    

    //3.返回cell

    return cell;

}

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值