ios清除图片缓存

(1)pod或者导入三方SDWebImage

 

 

(2)计算缓存大小以便在列表中显示

 

    NSUInteger bytesCache = [[SDImageCache sharedImageCache] getSize];

    //换算成 MB (注意iOS中的字节之间的换算是1000不是1024)

    float MBCache = bytesCache/1000/1000;

    NSString *cacheStr = [NSString stringWithFormat:@"清除缓存(%.0fM)",MBCache];

    self.nameArr=[[NSMutableArray alloc]initWithObjects:@"个人资料",@"修改密码",cacheStr,@"关于我们", nil];

 

(3)点击清除缓存cell清除

 

            UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"确定清除缓存吗?" message:nil preferredStyle:UIAlertControllerStyleActionSheet];

            //创建一个取消和一个确定按钮

            UIAlertAction *actionCancle=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

            //因为需要点击确定按钮后改变文字的值,所以需要在确定按钮这个block里面进行相应的操作

            UIAlertAction *actionOk=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

                

                //清楚缓存

                [[SDImageCache sharedImageCache] clearDisk];

                [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];

                [SVProgressHUD showSuccessWithStatus:@"清除成功"];

                

                self.nameArr=[[NSMutableArray alloc]initWithObjects:@"个人资料",@"修改密码",@"清除缓存(0M)",@"关于我们", nil];

                [self.tableView reloadData];

            }];

            //将取消和确定按钮添加进弹框控制器

            [alert addAction:actionCancle];

            [alert addAction:actionOk];

            //添加一个文本框到弹框控制器

            //显示弹框控制器

            [self presentViewController:alert animated:YES completion:nil];

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值