美文网首页
iOS新手 SDWebImage 清除缓存方法

iOS新手 SDWebImage 清除缓存方法

作者: 梧桐g110387 | 来源:发表于2016-12-02 13:22 被阅读0次

    //清除缓存

    • (float)checkTmpSize;

    - (float)checkTmpSize {
    
    float totalSize = 0;
    
    NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:_diskCachePath];
    
    for (NSString *fileName in fileEnumerator) {
    
    NSString *filePath = [_diskCachePath stringByAppendingPathComponent:fileName];
    
    NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
    
    unsigned long long length = [attrs fileSize];
    
    totalSize += length / 1024.0 / 1024.0;
    
    }
    
    NSLog(@"tmp size is %.2fM",totalSize);
    
    return totalSize;
    
    }
    
    #import "SDImageCache.h"
    
    CGFloat s = [[SDImageCache sharedImageCache] checkTmpSize];
    
    cell.lLabel.text = [NSString stringWithFormat:@"%.2fMB",s];
    ```
    ```
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
    if (indexPath.section == 0 && indexPath.row == 0) {
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定要清除缓存么" delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"清除", nil];
    
    alert.tag = 100;
    
    [alert show];
    
    }
    
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    
    switch (buttonIndex) {
    
    case 0:
    
    break;
    
    case 1:
    
    [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
    
    //                [CHNotices noticesWithTitle:@"删除成功" Time:1 View:self.view Style:CHNoticesStyleSuccess];
    
    NSLog(@"123121234412412412");
    
    [self.tableView reloadData];
    
    }];
    
    break;
    
    }
    
    }
    ```

    相关文章

      网友评论

          本文标题:iOS新手 SDWebImage 清除缓存方法

          本文链接:https://www.haomeiwen.com/subject/nrtqmttx.html