#pragma mark - 计算缓存大小
- (NSString *)getCacheSize
{
//定义变量存储总的缓存大小
long long sumSize = 0;
//01.获取当前图片缓存路径
NSString *cacheFilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];
//02.创建文件管理对象
NSFileManager *filemanager = [NSFileManager defaultManager];
//获取当前缓存路径下的所有子路径
NSArray *subPaths = [filemanager subpathsOfDirectoryAtPath:cacheFilePath error:nil];
//遍历所有子文件
for (NSString *subPath in subPaths) {
//1).拼接完整路径
NSString *filePath = [cacheFilePath stringByAppendingFormat:@"/%@",subPath];
//2).计算文件的大小
long long fileSize = [[filemanager attributesOfItemAtPath:filePath error:nil]fileSize];
//3).加载到文件的大小
sumSize += fileSize;
}
float size_m = sumSize/(1000*1000);
return [NSString stringWithFormat:@"%.2fM",size_m];
}
#pragma mark - 清除缓存提示(UITableViewDataSourceDelegate)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"缓存清除" message:@"确定清除缓存?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
[alertView show];
}
}
#pragma mark - UIAlertViewDelegate方法实现
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"代码执行到此");
//判断点击的是确认键
if (buttonIndex == 1) {
//01......
NSFileManager *fileManager = [NSFileManager defaultManager];
//02.....
NSString *cacheFilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];
//03......
[fileManager removeItemAtPath:cacheFilePath error:nil];
//04刷新第一行单元格
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
[_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
//05 :04和05使用其一即可
[_tableView reloadData];//刷新表视图
}
@pragma -mark -放置于.m文件首段较为合适,本DEMO仅做功能性展示,实时监测缓存大小,从其他界面跳转到本页面,也需要刷新下表视图
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[_tableView reloadData];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有