- 要实现的 协议----------------- tableview协议
- cellForRow------------------- 文字 和 量
- didSelectRow---------------- 点击 事件 调用 清除方法
import <UIImageView+WebCache.h>
import "MBProgressHUD+JFProgressHUD.h"
static NSString *ID = @"cell";
<UITableViewDelegate, UITableViewDataSource>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
}
cell.textLabel.text = @"清理缓存";
CGFloat size = [[SDImageCache sharedImageCache] getSize];
//显示 缓存的 量:0.88M
cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2lfM",size / 1024 / 1024];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self clearDisk];
}
- (void)clearDisk {
// 弹框 设置
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确定清除图片数据缓存吗?" preferredStyle:UIAlertControllerStyleAlert];
// 取消
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
// 确定
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
__weak typeof(self) weakSelf = self;
// 清理图片缓存
[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
[weakSelf.rootTableView reloadData];
[MBProgressHUD myi_promptHudWithShowHUDAddedTo:self.view message:@"清理缓存完成!"];
}];
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}