• SDWebImage


    SDWebImage是一个可以自动管理图片加载的类库 --- 图片加载非常耗费流量 --- 在移动平台上要非常小心 --- 本地缓存

    》SDWenImage功能强大 --- 有一个UIImageView的category,用法简单

    - (void)setImageWithURL:(NSURL *)url 
    

     》SDWebImageManager,使用它可以进行一些异步加载的工作,参考文档:

    https://github.com/rs/SDWebImage#readme

    SDWebImage --- 简化网络图片出路

    1》导入UIImageView+WebCache,调用TableView的数据源代理方法- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;用sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder 异步加载图片

    #import "UIImageView+WebCache.h"
    
    ...
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *cell_id = @"myTableViewCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id forIndexPath:indexPath];
    
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                           reuseIdentifier:MyIdentifier] autorelease];
        }
    // 给imageView异步加载图片
       [cell.imageView sd_setImageWithURL:[NSURL URLWithString:self.pictureStringArray[indexPath.row]] placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    
    
        cell.textLabel.text = @"111;
        return cell;
    }
    

     2》SDWebImageManager

         The SDWebImageManager is the class behind the UIImageView+WebCache category. It ties theasynchronous downloader with the image cache store. You can use this classe directly to benefitsfrom web image downloading with caching in another context than a UIView

         下面是如何使用SDWebImageManager一个简单的例子

    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    
    UIImage *cachedImage = [manager imageWithURL:url];
    
    if (cachedImage)
    {
        // Use the cached image immediatly
    }
    else
    {
        // Start an async download
        [manager downloadWithURL:url delegate:self];
    }
    

      》遵守SDWebImageManagerDelegate协议,实现webImageManager:didFinishWithImage:

    - (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image
    {
        // Do something with the downloaded image
    }
    
  • 相关阅读:
    springMVC数据绑定入门
    网易云课堂js学习笔记
    Java MyBatis insert数据库数据后返回主键
    (转)关于离职
    mybatis异常:Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for。。。。。。
    tomcat端口号被占用的问题
    tomcat中catalina是什么
    通过代码实现创建、删除、文件的读、写
    HNOI2008玩具装箱 斜率优化
    [ZJOI2008]骑士
  • 原文地址:https://www.cnblogs.com/bachl/p/4692938.html
Copyright © 2020-2023  润新知