




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
【移動(dòng)應(yīng)用開(kāi)發(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.添加手勢(shì)監(jiān)聽(tīng)//計(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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 心電圖操作流程質(zhì)量控制
- 五年級(jí)下冊(cè)寫(xiě)人作文《那一刻,我長(zhǎng)大了》范文
- 小學(xué)一年級(jí)語(yǔ)文教研組課外活動(dòng)安排計(jì)劃
- 小學(xué)教導(dǎo)處后勤協(xié)調(diào)職責(zé)
- 礦業(yè)企業(yè)人員穩(wěn)定性保障措施
- 六年級(jí)英語(yǔ)多媒體教學(xué)計(jì)劃
- 小學(xué)疫情防控班主任突發(fā)事件應(yīng)對(duì)工作總結(jié)范文
- 商業(yè)銀行信貸審批壓力測(cè)試流程他
- 城市燃?xì)饧夹g(shù)培訓(xùn)實(shí)習(xí)報(bào)告范文
- 醫(yī)藥行業(yè)材料供應(yīng)計(jì)劃和保障措施
- 小學(xué)數(shù)學(xué)教學(xué)案例分析 (一)
- 裝修公司掛靠協(xié)議書(shū)范本
- 《阿爾茨海默病的護(hù)理》課件
- 2025春季學(xué)期國(guó)開(kāi)電大??啤度宋挠⒄Z(yǔ)1》一平臺(tái)在線形考(綜合測(cè)試)試題及答案
- 2025-2030中國(guó)水晶玻璃茶具行業(yè)市場(chǎng)發(fā)展現(xiàn)狀及競(jìng)爭(zhēng)格局與投資前景研究報(bào)告
- 電磁兼容(EMC)培訓(xùn)資料
- 大學(xué)生職業(yè)規(guī)劃大賽《日語(yǔ)專業(yè)》生涯發(fā)展展示
- 缺陷檢測(cè)研究
- 四個(gè)維度讀懂總書(shū)記貴州之行PT課件
- T-FJSN 0003-2024 干手器標(biāo)準(zhǔn)規(guī)范
- 2024-2025學(xué)年慶陽(yáng)市數(shù)學(xué)五下期末質(zhì)量檢測(cè)模擬試題含答案
評(píng)論
0/150
提交評(píng)論