iOS 用 SDWebImage 清理图片缓存
效果图如下:
1.找到 SDWebImage找到SDImageCache类
2.添加如下方法
- (float)checkTmpSize
{
float totalSize = ;
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:_diskCachePath];
for (NSString *fileName in fileEnumerator)
{
NSString *filePath = [_diskCachePath stringByAppendingPathComponent:fileName]; NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; unsigned long long length = [attrs fileSize]; totalSize += length / 1024.0 / 1024.0;
}
// NSLog(@"tmp size is %.2f",totalSize); return totalSize;
}
具体用tableView实现
MoreViewController.h
#import "BaseViewController.h"
#import "More.h"
@interface MoreViewController : BaseViewController<UITableViewDataSource,UITableViewDelegate> @property(strong,nonatomic)UITableView *MoreTableView;
@property(strong,nonatomic)NSArray *arrayTitle;
@property(strong,nonatomic)NSArray *arrayImage; @end
MoreViewController.m
#import "MoreViewController.h" @interface MoreViewController ()
@property(strong,nonatomic)UILabel *lbl;
@end @implementation MoreViewController - (void)viewDidLoad {
[super viewDidLoad];
self.title=@"更多";
[self _loadData];
NSLog(@"%@",NSHomeDirectory());
} -(void)_loadData
{
// 设置tableview的title和image
self.arrayTitle=@[@"清除缓存",@"给个评价",@"商务合作",@"检测行版本",@"欢迎页",@"关于"];
self.arrayImage=@[@"moreClear@2x",@"moreScore@2x",@"moreBusiness@2x",@"moreVersion@2x",@"moreWelcome@2x",@"moreAbout@2x"];
// 初始化UItableView
self.MoreTableView=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
// 设置UItableView的背景色
self.MoreTableView.backgroundColor=[UIColor blackColor];
// 指定代理
self.MoreTableView.delegate=self;
self.MoreTableView.dataSource=self;
// 分割线的样式
self.MoreTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
[self.view addSubview:self.MoreTableView];
// 指定唯一标识符
[self.MoreTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"MoreTableCell"];
self.lbl=[[UILabel alloc]init];
self.lbl.textColor=[UIColor whiteColor];
} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.arrayTitle.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MoreTableCell" forIndexPath:indexPath];
if (indexPath.row==) {
self.lbl.frame= CGRectMake(,,, cell.frame.size.height*0.5);
self.lbl.text=[NSString stringWithFormat:@"缓存为%.2fMB",[[SDImageCache sharedImageCache] checkTmpSize]];
[cell addSubview:self.lbl];
} // 设置Cell的背景色
cell.backgroundColor=[UIColor blackColor];
// 设置title的文字颜色
cell.textLabel.textColor=[UIColor whiteColor];
cell.textLabel.text=self.arrayTitle[indexPath.row];
cell.imageView.image=[UIImage imageNamed:self.arrayImage[indexPath.row]]; return cell;
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
} #pragma Mark - 选中跳转
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==) {
[self alertView]; }else if (indexPath.row==){
EvaluationViewController *evaluation=[EvaluationViewController new];
[self.navigationController pushViewController:evaluation animated:YES];
}
else if (indexPath.row==){
BusinessViewController *business=[BusinessViewController new];
[self.navigationController pushViewController:business animated:YES]; }else if (indexPath.row==){
VersionViewController *version=[VersionViewController new];
[self.navigationController pushViewController:version animated:YES]; }else if (indexPath.row==){
WelcomeViewController *welcome=[WelcomeViewController new];
[self.navigationController pushViewController:welcome animated:YES];
}else{
AboutViewController *about=[AboutViewController new];
[self.navigationController pushViewController:about animated:YES];
} } #pragma Mark - 弹出框
-(void)alertView
{
NSLog(@"-----");
float tmpSize=[[SDImageCache sharedImageCache] checkTmpSize]; UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"清理缓存(%.2fM)",tmpSize] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// 清除磁盘
[[SDImageCache sharedImageCache] clearDisk];
// 刷新数据
[self.MoreTableView reloadData];
}]; UIAlertAction *cancle=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:ok];
[alert addAction:cancle];
[self presentViewController:alert animated:YES completion:nil];
} #pragma Mark - 整体刷新
-(void)viewWillAppear:(BOOL)animated
{
//
[super viewWillAppear:YES];
[self.MoreTableView reloadData];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; } @end
iOS 用 SDWebImage 清理图片缓存的更多相关文章
- SDWebImage清理图片缓存方法
//获取当前缓存大小 @property (nonatomic, assign) NSUInteger tmpSize; //获取缓存大小并储存 _tmpSize=[[SDImageCache sha ...
- SDWebImage实现图片缓存
我之前写过一篇博客,介绍缓存处理的三种方式,其中最难,最麻烦,最占内存资源的还是图片缓存,最近做的项目有大量的图片处理,还是采用了SDWebImage来处理,但是发现之前封装好的代码报错了.研究发现, ...
- iOS网络加载图片缓存策略之ASIDownloadCache缓存优化
iOS网络加载图片缓存策略之ASIDownloadCache缓存优化 在我们实际工程中,很多情况需要从网络上加载图片,然后将图片在imageview中显示出来,但每次都要从网络上请求,会严重影响用 ...
- Fast Image Cache – iOS 应用程序高性能图片缓存
Fast Image Cache 是一种在 iOS 应用程序中高效.持续.超快速的存储和检索图像的解决方案.任何良好的 iOS 应用程序的用户体验都应该是快速,平滑滚动的,Fast Image Cac ...
- iOS网络加载图片缓存与SDWebImage
加载网络图片可以说是网络应用中必备的.如果单纯的去下载图片,而不去做多线程.缓存等技术去优化,加载图片时的效果与用户体验就会很差. 一.自己实现加载图片的方法 tips: *iOS中所有网络访问都是异 ...
- iOS之SDWebImage清理缓存
.找到 SDWebImage找到SDImageCache类 添加如下方法 - (float)checkTmpSize { float totalSize = 0; NSDirectoryEnumera ...
- SDWebImage清除图片缓存
背景: 使用 SDWebImage 库,由于内存中一直缓存着加载的图片,而导致内存过高(我们无法手动管理内存),弹出内存警告而导致程序很卡或者直接crash掉. 我的解决方法: 在AppDelegat ...
- iOS中 SDWebImage手动清除缓存的方法 技术分享
1.找到SDImageCache类 2.添加如下方法: - (float)checkTmpSize { float totalSize = 0; NSDirectoryEnumerator *file ...
- iOS利用SDWebImage实现缓存的计算与清理
概述 可以仅仅清理图片缓存, 也可以清理所有的缓存文件(包括图片.视频.音频等). 详细 代码下载:http://www.demodashi.com/demo/10717.html 一般我们项目中的缓 ...
随机推荐
- ASP.NET MVC之如何看待内置配置来提高性能优化(四)
前言 前几篇我们比较基础的讲了下MVC中的知识,这一节我们穿插点知识,讲讲MVC中我们可以提高性能的办法. Razor视图引擎优化(优化一) 我们知道默认情况下配置MVC去解析一个视图会首先约定通过查 ...
- Linux模块
一.为什么要使用模块 由于linux使用的是整体结构,不是模块化的结构,整体结构实现的操作系统可扩展性差.linux为了扩展系统,使用了模块的技术,模块能够从系统中动态装入和卸载,这样使得linux也 ...
- IDDD 实现领域驱动设计-一个简单的 CQRS 示例
上一篇:<IDDD 实现领域驱动设计-CQRS(命令查询职责分离)和 EDA(事件驱动架构)> 学习架构知识,需要有一些功底和经验,要不然你会和我一样吃力,CQRS.EDA.ES.Saga ...
- php创建新用户注册界面布局实例
php创建新用户注册界面布局实例 <!DOCTYPE> <html> <head> <title>Load page</title> < ...
- PHP环境配置-从Apache官网下载windows版apache服务器
由于个人有强迫倾向,下载软件都喜欢从官网下载,摸索了好久终于摸清楚怎么从Apache官网下载windows安装版的Apache服务器了,现在分享给大家. 进入apache服务器官网http://htt ...
- 使用 Spring Boot 快速构建 Spring 框架应用--转
原文地址:https://www.ibm.com/developerworks/cn/java/j-lo-spring-boot/ Spring 框架对于很多 Java 开发人员来说都不陌生.自从 2 ...
- 把《c++ primer》读薄(3-2 标准库vector容器+迭代器初探)
督促读书,总结精华,提炼笔记,抛砖引玉,有不合适的地方,欢迎留言指正. 标准库vector类型初探,同一种类型的对象的集合(类似数组),是一个类模版而不是数据类型,学名容器,负责管理 和 存储的元素 ...
- ZOJ Problem Set - 1337 Pi 最大公约数
这道题目的关键在于怎么求两个整数的最大公约数,这里正好复习一下以前的知识,如下: 1.设整数a和b 2.如果a和b都为0,则二者的最大公约数不存在 3.如果a或b等于0,则二者的最大公约数为非0的一个 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- 《HelloGitHub月刊》第07期
最近工作上的事比较多,<HelloGitHub>月刊第07期拖到月底才发. 本期月刊对logo和月刊的排版进行了优化,不知道大家的反馈如何,还望大家多多反馈,让<HelloGitHu ...