035-处理图片 缓存 以及 退出登录

  • 要实现的 协议----------------- 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];
}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,086评论 3 38
  • 1.OC里用到集合类是什么? 基本类型为:NSArray,NSSet以及NSDictionary 可变类型为:NS...
    轻皱眉头浅忧思阅读 1,393评论 0 3
  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,203评论 30 471
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,452评论 9 5
  • 窃读记 有书的日子里,花是花,草是草,人是人,我是我! 父亲爱读书,每天晚上睡觉前,就躺在被窝里看借来的书,直到鼾...
    一枚冰儿阅读 289评论 1 1