ioS 计算缓存和清除缓存
来源:互联网 发布:手机淘宝助理在哪里找 编辑:程序博客网 时间:2024/05/22 12:00
转载:http://www.tuicool.com/articles/nuaERjQ
#pragma mark - 计算缓存大小 2 - (NSString *)getCacheSize 3 { 4 //定义变量存储总的缓存大小 5 long long sumSize = 0; 6 7 //01.获取当前图片缓存路径 8 NSString *cacheFilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"]; 9 10 //02.创建文件管理对象11 NSFileManager *filemanager = [NSFileManager defaultManager];12 13 //获取当前缓存路径下的所有子路径14 NSArray *subPaths = [filemanager subpathsOfDirectoryAtPath:cacheFilePath error:nil];15 //遍历所有子文件16 for (NSString *subPath in subPaths) {17 //1).拼接完整路径18 NSString *filePath = [cacheFilePath stringByAppendingFormat:@"/%@",subPath];19 //2).计算文件的大小20 long long fileSize = [[filemanager attributesOfItemAtPath:filePath error:nil]fileSize];21 //3).加载到文件的大小22 sumSize += fileSize;23 }24 float size_m = sumSize/(1000*1000);25 return [NSString stringWithFormat:@"%.2fM",size_m];26 27 }28 #pragma mark - 清除缓存提示(UITableViewDataSourceDelegate)29 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath30 {31 if (indexPath.row == 0) {32 UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"缓存清除" message:@"确定清除缓存?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];33 [alertView show];34 }35 }36 #pragma mark - UIAlertViewDelegate方法实现37 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex38 {39 NSLog(@"代码执行到此");40 //判断点击的是确认键41 if (buttonIndex == 1) {42 //01......43 NSFileManager *fileManager = [NSFileManager defaultManager];44 //02.....45 NSString *cacheFilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];46 //03......47 [fileManager removeItemAtPath:cacheFilePath error:nil];48 49 //04刷新第一行单元格50 NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];51 [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];52 53 //05 :04和05使用其一即可54 [_tableView reloadData];//刷新表视图55 }56 @pragma -mark -放置于.m文件首段较为合适,本DEMO仅做功能性展示,实时监测缓存大小,从其他界面跳转到本页面,也需要刷新下表视图57 - (void)viewWillAppear:(BOOL)animated58 {59 [super viewWillAppear:YES];60 [_tableView reloadData];61 }
0 0
- ioS 计算缓存和清除缓存
- iOS中的缓存计算和清除
- iOS计算缓存文件大小, 和清除缓存功能
- IOS 之 计算缓存,清除缓存
- iOS计算缓存大小、清除缓存
- iOS计算缓存大小、清除缓存
- 计算缓存大小和清除缓存
- Xcode计算缓存文件大小和清除缓存
- Android 计算缓存大小和清除缓存
- Android计算缓存大小和清除缓存
- 计算和清除webview缓存
- iOS中的缓存计算和清除(二)
- iOS数据缓存和清除
- 清除缓存,计算缓存大小
- 清除缓存计算缓存大小
- 计算缓存与清除缓存
- 计算缓存大小+清除缓存
- IOS开发——ASIDownloadCache计算缓存大小&清除缓存
- 怎样在 Ubuntu 中修改默认程序
- C++在函数声明时,后面跟个const是什么意思?
- varchar2() 与 nvarchar2() 与 char() 与 nchar()区别与联系
- HDU-5821 <2016 Multi-University Training 8> Ball (贪心)
- android按两次返回键退出程序
- ioS 计算缓存和清除缓存
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
- HDU 1257 最少拦截系统(LIS)
- Java_文件上传与下载(三)
- Python 实现Linux间远程拷贝Scp不用输入密码问题
- H5 压缩图片上传(pc端适用)支持png/jpg格式(其他格式都会转为png)
- 1046: 最小的K个数
- freemarker使用技巧
- HDU 2063 过山车 [二分图匹配] [匈牙利算法]