- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// 设置加载视图
UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[loadingView startAnimating];
self.accessoryView = loadingView;
//设置文字
self.textLabel.text = @"清楚缓存";
self.detailTextLabel.text = @"正在计算";
}
return self;
}
unsigned long long size =
[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:@"CustomFile"].fileSize;
//fileSize是封装在Category中的。
size += [SDImageCache sharedImageCache].getSize; //CustomFile + SDWebImage 缓存
//设置文件大小格式
NSString sizeText = nil;
if (size >= pow(10, 9)) {
sizeText = [NSString stringWithFormat:@"%.2fGB", size / pow(10, 9)];
}else if (size >= pow(10, 6)) {
sizeText = [NSString stringWithFormat:@"%.2fMB", size / pow(10, 6)];
}else if (size >= pow(10, 3)) {
sizeText = [NSString stringWithFormat:@"%.2fKB", size / pow(10, 3)];
}else {
sizeText = [NSString stringWithFormat:@"%zdB", size];
}
//计算完成后,回到主线程继续处理,显示文件大小,除去加载视图,显示箭头,添加点击事件
dispatch_async(dispatch_get_main_queue(), ^{
self.detailTextLabel.text = [NSString stringWithFormat:@"%@",sizeText];
self.accessoryView = nil;
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clearCacheClick)]];
});
- (void)clearCacheClick
{
[SVProgressHUD showWithStatus:@"正在清除缓存···"];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSFileManager *mgr = [NSFileManager defaultManager];
[mgr removeItemAtPath:GYLCustomFile error:nil];
[mgr createDirectoryAtPath:GYLCustomFile withIntermediateDirectories:YES attributes:nil error:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
// 设置文字
self.detailTextLabel.text = nil;
});
});
}];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有