Thinking: Building the UI with a static cell, and then fetching the cached data, the third party resource clears the cache
Static cells------Less: Features: Cell no longer used, only in the tabaleviewcontroller inside with the advantages: do not need to implement protocol methods
Build the UI in storyboard, change the controller's content options to static, use the grouping style, add UI controls to the top, and build a good appearance;
Clear Cache
1, the calculation cache size: Caching: Each app has a corresponding sandbox, storing pictures cached from the network, clearing the cache first to get the size of the data in the sandbox; train of thought://1, find sandbox path//2, mosaic out cache path//3, File housekeeper (single Case object) 4, with the file housekeeper to remove all the files of the path//5, Traversal path: Splicing path-"Get file attributes-" Take to File size---"Add up to achieve:
-(void) _countcachesize
{
Find the Sandbox path
NSString *homepath = Nshomedirectory ();
Stitching out the cache path
NSString *imgspath = [HomePath stringbyappendingpathcomponent:@ "library/caches/default/ Com.hackemist.SDWebImageCache.default "];
File Steward (single Case object)
Nsfilemanager *manager = [Nsfilemanager Defaultmanager];
Use the file housekeeper to remove all of the child file paths
Nserror *error = nil;
Nsarray *arr = [Manager Subpathsofdirectoryatpath:imgspath error:&error];
Long long sum = 0;
Traversal path: Splicing path--"Get File attributes--" take to File size---"Add up
For (NSString *path in arr) {
Stitching paths
NSString *filepath = [Imgspath Stringbyappendingpathcomponent:path];
Get file properties
Nsdictionary *dic = [Manager Attributesofitematpath:filepath error:&error];
Take to File size
NSNumber *filesize = dic[nsfilesize];
Sum + = [fileSize longlongvalue];
}
CacheSize = SUM/(1024.0 * 1024);
}
2, display the current cache size
Only the first row of cells has a cached label, so in the method that the cell will appear, we judge the first row of cells, take the label, and assign the value to display
When the cell will be displayed
-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: (NSIndexPath *) Indexpath
{
if (Indexpath = = 0) {
[Self _countcachesize];
Uilabel *label = (Uilabel *) [cell viewwithtag:100];
Label.text = [NSString stringwithformat:@ "%.1FM", cacheSize];
}
}
3, clear the cache
When you click on the first cell, an alert view pops up, asks if it's cleared, clicks OK, and sdwebimage through the third party resource.
[[Sdimagecachesharedimagecache]cleardisk]; implementation of cache cleanup
Realize:
How to trigger a cell
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
{
if (Indexpath.row = = 0) {
Popup Clear Confirmation Box
Uialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@ "Warning" message:@ "OK Clear" PreferredStyle: Uialertcontrollerstylealert];
Uialertaction *cancelaction = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel Handler:nil];
[Alert addaction:cancelaction];
Uialertaction *sureaction = [uialertaction actionwithtitle:@ "OK" Style:uialertactionstyledefault handler:^ ( Uialertaction *action) {
Determine clear Cache
[[Sdimagecache Sharedimagecache] cleardisk];
Refresh TableView
[Self.tableview Reloaddata];
}];
[Alert addaction:sureacrion];
[Self Presentviewcontroller:alert animated:yes completion:nil];
}
}