The specific effect is as follows
1. Find Sdwebimage Find Sdimagecache class
Add the following methods
- (float) checktmpsize{floatTotalSize =0; Nsdirectoryenumerator*fileenumerator =[[Nsfilemanager Defaultmanager] enumeratoratpath:_diskcachepath]; for(NSString *filenameinchfileenumerator) {NSString*filepath =[_diskcachepath Stringbyappendingpathcomponent:filename]; Nsdictionary*attrs =[[Nsfilemanager Defaultmanager] Attributesofitematpath:filepath Error:nil]; unsignedLong LongLength =[Attrs fileSize]; TotalSize+ = length/1024.0/1024.0; } //NSLog (@ "tmp size is%.2f", totalsize); returntotalsize;}
Specifically implemented with TableView
#import <UIKit/UIKit.h>@interface moreviewcontroller:uitableviewcontroller< uitableviewdelegate,uitableviewdatasource>@end
#import "MoreViewController.h"@interfaceMoreviewcontroller () @property (nonatomic,strong) Nsarray*Titlemore, @property (nonatomic,strong) Nsarray*image; @property (nonatomic,assign) Nsindexpath*Indexpath, @property (nonatomic,strong) UILabel*lbl, @property (nonatomic,assign)floatmpsize;@end@implementationMoreviewcontroller- (void) viewdidload {[Super viewdidload]; Self.navigationItem.title=@"more"; Self.titlemore[Email protected] [@"Clear Cache",@"give me a comment .",@"Business Cooperation",@"Detect new version",@"Welcome Page",@"about the"]; Self.image[Email protected] [@"Moreclear",@"Morescore",@"morebusiness",@"moreversion",@"Morewelcome",@"moreabout"]; Self.tableView.backgroundColor=[Uicolor Blackcolor]; Self.tableView.scrollEnabled=NO; [Self.tableview Registerclass:[uitableviewcellclass] 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{returnSelf.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] checktmpsize]; Self.lbl.frame=cgrectmake ( $,Ten, $,Ten); [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]; returncell; }- (void) Viewwillappear: (BOOL) animated{[Super Viewwillappear:yes]; [Self.tableview reloaddata];}//pop-up box determines whether to clear the cache-(void) alertview{NSLog (@"----"); floatTmpsize=[[Sdimagecache Sharedimagecache] checktmpsize]; Uialertcontroller*alert=[uialertcontroller Alertcontrollerwithtitle:@"Tips"Message:[nsstring stringWithFormat:@"Clean Up cache (%.2FM)", Tmpsize] preferredstyle:uialertcontrollerstylealert]; Uialertaction*ok=[uialertaction Actionwithtitle:@"Determine"Style:uialertactionstyledefault handler:^ (Uialertaction *_nonnull Action) {[[Sdimagecache Sharedimagecache] cleardisk];//[Self.tableview Reloadrowsatindexpaths:@[self.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 the 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 n avigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [s] Egue Destinationviewcontroller]. Pass the selected object to the new view controller.}*/@end
IOS cleans up picture cache with Sdwebimage