多线程06-(sdwebimage 总结3)
生活随笔
收集整理的這篇文章主要介紹了
多线程06-(sdwebimage 总结3)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2.SDWebImage
1> 常用方法
- (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;2> 內(nèi)存處理:當app接收到內(nèi)存警告時
/*** 當app接收到內(nèi)存警告*/
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{SDWebImageManager *mgr = [SDWebImageManager sharedManager];// 1.取消正在下載的操作[mgr cancelAll];// 2.清除內(nèi)存緩存[mgr.imageCache clearMemory];
}3> SDWebImageOptions
* SDWebImageRetryFailed : 下載失敗后,會自動重新下載
* SDWebImageLowPriority : 當正在進行UI交互時,自動暫停內(nèi)部的一些下載操作
* SDWebImageRetryFailed | SDWebImageLowPriority : 擁有上面2個功能
//
// HMAppsViewController.m
// 01-cell圖片下載(了解)
//
// Created by apple on 14-9-18.
// Copyright (c) 2014年 heima. All rights reserved.
//#import "HMAppsViewController.h"
#import "HMApp.h"
#import "UIImageView+WebCache.h"@interface HMAppsViewController ()
/*** 所有的應用數(shù)據(jù)*/
@property (nonatomic, strong) NSMutableArray *apps;
@end@implementation HMAppsViewController#pragma mark - 懶加載
- (NSMutableArray *)apps
{if (!_apps) {// 1.加載plistNSString *file = [[NSBundle mainBundle] pathForResource:@"apps" ofType:@"plist"];NSArray *dictArray = [NSArray arrayWithContentsOfFile:file];// 2.字典 --> 模型NSMutableArray *appArray = [NSMutableArray array];for (NSDictionary *dict in dictArray) {HMApp *app = [HMApp appWithDict:dict];[appArray addObject:app];}// 3.賦值self.apps = appArray;
// _apps = appArray;}return _apps;
}#pragma mark - 初始化方法
- (void)viewDidLoad
{[super viewDidLoad];}- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];}#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return self.apps.count;
}- (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"];
// [cell.imageView sd_setImageWithURL:url placeholderImage:placeholder];// [cell.imageView sd_setImageWithURL:url placeholderImage:placeholder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
// NSLog(@"----圖片加載完畢---%@", image);
// }];SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageLowPriority;[cell.imageView sd_setImageWithURL:url placeholderImage:placeholder options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) { // 這個block可能會被調(diào)用多次NSLog(@"下載進度:%f", (double)receivedSize / expectedSize);} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {NSLog(@"----圖片加載完畢---%@", image);}];return cell;
}
@end
總結(jié)
以上是生活随笔為你收集整理的多线程06-(sdwebimage 总结3)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 蝉花与冬虫夏草的比较
- 下一篇: Redis的SpringBoot配置(R