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


扫描二维码关注公众号,回复: 947581 查看本文章

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












猜你喜欢

转载自blog.csdn.net/dangbai01_/article/details/80321726