zoukankan      html  css  js  c++  java
  • UI第十七讲.图片异步加载(包括第三方), KVO, KVC

     一、异步下载图片二、UITableView中图片的异步下载

    示例代码:

    图片解析,并利用第三方方法对图片进行异步加载

    #import "ViewController.h"
    #import "TableViewCell.h"
    #import "NetWorkHandle.h"
    #import "Model.h"
    #import "UIImageView+WebCache.h"
    @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
    
    //@property(nonatomic,strong)UIImageView *imagev;
    
    @property(nonatomic,strong)UITableView *tableView;
    
    @property(nonatomic,strong)NSMutableArray *dataArray;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        
        [self loadTableView];
        [self loadPOSTImage];
     
        
    }
    
    -(void)loadTableView
    {
    
        self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.view addSubview:self.tableView];
       
        //注意这里要写自己定义的tableViewCell
         [self.tableView registerClass:[TableViewCell class]forCellReuseIdentifier:@"CELL"];
        
    
    }
    
    //自定义高度********************
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 120;
        
    }
    
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.dataArray.count;
    
    }
    
    //对图片到的的解析,和利用第三方进行异步加载
    -(void)loadPOSTImage
    {
        self.dataArray  = [NSMutableArray array];
        NSString *str = @"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php";
        
        //用封装对的GET/POST异步进行加载
        [NetWorkHandle getDataWithURLString:str compare:^(id object) {
            //用字典接收请求下来的数据
            NSDictionary *dic = object;
            //用数组取出字典中的数据
            NSArray *arr = dic[@"events"];
            
            //利用for/in进行遍历
            for (NSDictionary *dict in arr) {
                //先初始化
                Model *model = [[Model alloc] init];
                //然后用model取出字典中的数据
                [model setValuesForKeysWithDictionary:dict];
                //将model中数据添加进数组
                [self.dataArray addObject:model];
            }
            
            [self.tableView reloadData];
        }];
    
    }
    
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL" forIndexPath:indexPath];
        
        
        Model *model = self.dataArray[indexPath.row];
        
    
        //SDWebImage 功能:1.缓存,1.异步加载
        //使用第三方进行图片的设置
        [cell.myImageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
        
          cell.label.text = model.title;
      
        return cell;
    
    
    }

    三、KVO

    四、KVO监测Model图片下载

  • 相关阅读:
    ASP获取上月本月下月的第一天和最后一天
    JS表单提交
    JS分段传输数据
    SQLServer存储过程实现单条件分页
    ASP从HTML标签中提取中文
    ViewData、ViewBag和 TempData
    Java 第十一届 蓝桥杯 省模拟赛 小明的城堡
    Java实现DFS深度优先查找
    Java实现BFS广度优先查找
    Java实现二分查找(折半查找)
  • 原文地址:https://www.cnblogs.com/erdeng/p/4865390.html
Copyright © 2011-2022 走看看