codeTools

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

2017-03-08  本文已影响11人  ArrQing

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];
}


上一篇 下一篇

猜你喜欢

热点阅读