IOS cleans up picture cache with Sdwebimage

Source: Internet
Author: User

The specific effect is as follows

1. Find Sdwebimage Find Sdimagecache class

Add the following methods

-(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%.2f", totalsize);        return totalsize;}

Specifically implemented with TableView

#import <UIKit/UIKit.h> @interface Moreviewcontroller:uitableviewcontroller<uitableviewdelegate, Uitableviewdatasource> @end
#import "MoreViewController.h" @interface Moreviewcontroller () @property (nonatomic,strong) Nsarray *titlemore;@ Property (Nonatomic,strong) Nsarray *image; @property (nonatomic,assign) nsindexpath* Indexpath; @property (Nonatomic, Strong) UILabel *lbl; @property (nonatomic,assign) float mpsize; @end @implementation moreviewcontroller-(void)    viewdidload {[Super viewdidload];    [email protected] "more"; [Email protected]   [@ "Clear Cache" @ "Give a rating" @ "Business cooperation" @ "detect new version" @ "Welcome page" @ "about"]; [Email protected]    [@ "Moreclear", @ "Morescore", @ "morebusiness", @ "moreversion", @ "Morewelcome", @ "moreabout"];    Self.tableview.backgroundcolor=[uicolor Blackcolor];    Self.tableview.scrollenabled=no;    [Self.tableview Registerclass:[uitableviewcell class] forcellreuseidentifier:@ "more"];    Self.lbl=[[uilabel Alloc]init];  Self.lbl.textcolor=[uicolor Whitecolor]; }-(void) didreceivememorywarning {[Super didreceivememorywarning];} -(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return 1;} -(NsintEger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return self.titleMore.count;}      -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{        UITableViewCell *cell=[tableview dequeuereusablecellwithidentifier:@ "more" forindexpath:indexpath]; if (indexpath.row==0) {self.lbl.text=[nsstring stringwithformat:@ "cache is%.2FMB", [[Sdimagecache SharedImageCache] Ch        Ecktmpsize]];        Self.lbl.frame=cgrectmake (200, 10, 200, 10);    [Cell ADDSUBVIEW:SELF.LBL];    } cell.imageview.image=[uiimage Imagenamed:self.image[indexpath.row]];    Cell.textlabel.text=self.titlemore[indexpath.row];    Cell.textlabel.textcolor=[uicolor Whitecolor];    Cell.backgroundcolor=[uicolor Blackcolor];    return cell;    }-(void) Viewwillappear: (BOOL) animated{[Super Viewwillappear:yes]; [Self.tableview Reloaddata];}    The popup box determines whether to clear the cache-(void) alertview{NSLog (@ "----"); Float Tmpsize=[[sdimagecache Sharedimagecache] Checktmpsize]; Uialertcontroller *alert=[uialertcontroller alertcontrollerwithtitle:@ "hint" message:[nsstring stringWithFormat:@ "    Clean cache (%.2FM) ", Tmpsize] preferredstyle:uialertcontrollerstylealert]; Uialertaction *ok=[uialertaction actionwithtitle:@ "OK" style:uialertactionstyledefault handler:^ (UIAlertAction * _ Nonnull action) {[[Sdimagecache Sharedimagecache] cleardisk];//[Self.tableview reloadrowsatindexpaths:@[se        Lf.indexpath] Withrowanimation:uitableviewrowanimationfade];    [Self.tableview Reloaddata];        }];        Uialertaction *cancle=[uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstyledefault Handler:nil];    [Alert Addaction:ok];    [Alert addaction:cancle]; [Self Presentviewcontroller:alert animated:yes completion:nil];} Select first column-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{if (    indexpath.row==0) {[Self alertview]; }}/* #pragma mark-navigation//in a storyboard-based application, You'll often want to do a little preparation before navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender    :(ID) Sender {//Get the new view controller using [Segue Destinationviewcontroller]. Pass the selected object to the new view Controller.} */

IOS cleans up picture cache with Sdwebimage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.