




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
【移動(dòng)應(yīng)用開發(fā)技術(shù)】iOS中如何實(shí)現(xiàn)設(shè)置清除緩存功能
/upload/information/20200623/126/121396.png具體步驟1.創(chuàng)建自定義Cell,命名為GYLClearCacheCell-
(instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString
*)reuseIdentifier
{
if
(self
=
[super
initWithStyle:style
reuseIdentifier:reuseIdentifier])
{
//
設(shè)置加載視圖
UIActivityIndicatorView
*loadingView
=
[[UIActivityIndicatorView
alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[loadingView
startAnimating];
self.accessoryView
=
loadingView;
//設(shè)置文字
self.textLabel.text
=
@"清楚緩存";
self.detailTextLabel.text
=
@"正在計(jì)算";
}
return
self;
}2.計(jì)算緩存文件大小unsigned
long
long
size
=
[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask,
YES).lastObject
stringByAppendingPathComponent:@"CustomFile"].fileSize;
//fileSize是封裝在Category中的。
size
+=
[SDImageCache
sharedImageCache].getSize;
//CustomFile
+
SDWebImage
緩存
//設(shè)置文件大小格式
NSString
sizeText
=
nil;
if
(size
>=
pow(10,
9))
{
sizeText
=
[NSString
stringWithFormat:@"%.2fGB",
size
/
pow(10,
9)];
}else
if
(size
>=
pow(10,
6))
{
sizeText
=
[NSString
stringWithFormat:@"%.2fMB",
size
/
pow(10,
6)];
}else
if
(size
>=
pow(10,
3))
{
sizeText
=
[NSString
stringWithFormat:@"%.2fKB",
size
/
pow(10,
3)];
}else
{
sizeText
=
[NSString
stringWithFormat:@"%zdB",
size];
}3.添加手勢監(jiān)聽//計(jì)算完成后,回到主線程繼續(xù)處理,顯示文件大小,除去加載視圖,顯示箭頭,添加點(diǎn)擊事件
dispatch_async(dispatch_get_main_queue(),
^{
self.detailTextLabel.text
=
[NSString
stringWithFormat:@"%@",sizeText];
self.accessoryView
=
nil;
self.accessoryType
=
UITableViewCellAccessoryDisclosureIndicator;
[self
addGestureRecognizer:[[UITapGestureRecognizer
alloc]
initWithTarget:self
action:@selector(clearCacheClick)]];
});4.清除緩存-
(void)clearCacheClick
{
[SVProgressHUD
showWithStatus:@"正在清除緩存···"];
[SVProgressHUD
setDefaultMaskType:SVProgressHUDMaskTypeBlack];
[[SDImageCache
sharedImageCache]
clearDiskOnCompletion:^{
dispatch_async(dispatch_get_global_queue(0,
0),
^{
NSFileManager
*mgr
=
[NSFileManager
defaultManager];
[mgr
removeItemAtPath:GYLCustomFile
error:nil];
[mgr
createDirectoryAtPath:GYLCustomFile
withIntermediateDirectories:YES
attributes:nil
error:nil];
dispatch_async(dispatch_get_main_queue(),
^{
[SVProgressHUD
dismiss];
//
設(shè)置文字
self.detailTextLabel.text
=
nil;
});
});
}];
}5.其他注意點(diǎn)6.使用#import
"GYLSettingViewController.h"
#import
"GYLClearCacheCell.h"
@implementation
GYLSettingViewController
static
NSString
*
const
GYLClearCacheCellID
=
@"ClearCache";
static
NSString
*
const
GYLSettingCellID
=
@"Setting";
-
(instancetype)init
{
return
[self
initWithStyle:UITableViewStyleGrouped];
}
-
(void)viewDidLoad
{
[super
viewDidLoad];
self.view.backgroundColor
=
GYLBGColor;
self.navigationItem.title
=
@"設(shè)置";
[self.tableView
registerClass:[GYLClearCacheCell
class]
forCellReuseIdentifier:GYLClearCacheCellID];
[self.tableView
registerClass:[UITableViewCell
class]
forCellReuseIdentifier:GYLSettingCellID];
}
-
(NSInteger)numberOfSectionsInTableView:(UITableView
*)tableView
{
return
3;
}
-
(NSInteger)tableView:(UITableView
*)tableView
numberOfRowsInSection:(NSInteger)section
{
return
1;
}
-
(UITableViewCell
*)tableView:(UITableView
*)tableView
cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
if
(indexPath.section
==
0
&&
indexPath.row
==
0)
{
return
[[GYLClearCacheCell
alloc]
initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:GYLClearCacheCellID];
}
UITableViewCell
*cell
=
[tableView
dequeueReusableCellWithIdentifier:GYLSettingCellID];
cell.textLabel.text
=
[NSString
stringWithFormat:@"section-%zd,row--%zd",inde
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 土建瓦工勞務(wù)分包合同
- 常年法律顧問合同
- 詳細(xì)操作流程說明書
- 2025年撫州貨運(yùn)資格證模擬考試題庫下載
- 2025年徐州市汽車租賃合同5篇
- 農(nóng)莊農(nóng)場合作經(jīng)營合同協(xié)議書范本6篇
- 公司副食品購銷合同7篇
- 房地產(chǎn)開發(fā)聯(lián)營合同
- 專利技術(shù)的授權(quán)與使用條款協(xié)議
- 無償保管合同范本-倉儲保管合同8篇
- 中小學(xué)領(lǐng)導(dǎo)班子包級包組包班制度
- 汽車掛靠經(jīng)營合同協(xié)議書模板
- 基坑土方開挖專項(xiàng)施工方案(完整版)
- 電網(wǎng)工程設(shè)備材料信息參考價(jià)(2024年第四季度)
- 2025年江蘇農(nóng)牧科技職業(yè)學(xué)院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 數(shù)據(jù)中心運(yùn)維服務(wù)投標(biāo)方案(技術(shù)標(biāo))
- 2024-2025學(xué)年山東省濰坊市高一上冊1月期末考試數(shù)學(xué)檢測試題(附解析)
- 電玩城培訓(xùn)課件
- 2025年全年日歷-含農(nóng)歷、國家法定假日-帶周數(shù)豎版
- 小學(xué)生播音員課件
- 2024年重大事項(xiàng)內(nèi)部會(huì)審制度(3篇)
評論
0/150
提交評論