iOS中如何清除缓存?
来源:互联网 发布:吉林大学网络教育电话 编辑:程序博客网 时间:2024/05/21 11:12
本文和大家分享的主要是ios中缓存清除相关内容,一起来看看吧,希望对大家学习ios有所帮助。
很多app中都有清除缓存的功能,今天来说一下这种功能怎么操作,具体见如下代码:
首先一般清除缓存之前会有一个提示,是否清理缓存
#pragma mark -缓存处理
//清楚缓存调用
- (void)clearCacheAction {
UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"是否清理缓存"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
alert.tag=CLEARCACHE_ALERT_TAG;
[alertshow];
}
然后写提示的代理方法:
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(CLEARCACHE_ALERT_TAG== alertView.tag){
if(0== buttonIndex ){
}else{
[selfclearCache];
}
}
}
以下就是具体的清理缓存的方法了:
#pragma mark -
//清除缓存调用
- (void)clearCache {
[[[SDWebImageManagersharedManager]imageCache]clearDisk];
[[[SDWebImageManagersharedManager]imageCache]clearMemory];
[[CNToolsharedInstance]clearAllCache];
[selfpresentSuccessTips:@"缓存已清理"];
//修改显示数据
NSIndexPath*indexPath = [NSIndexPathindexPathForRow:0inSection:1];
SELFSettingDefaultCell*cell = [self.tableViewcellForRowAtIndexPath:indexPath];
cell.subTitle.text= [selfcalculateCacheSize];
}
显示出来的缓存大小是要计算的,计算方法如下:
//计算缓存大小
- (NSString*) calculateCacheSize {
NSIntegersize = [[SDImageCachesharedImageCache]getSize];
if(size<1024*1024*1024){//小于1G
CGFloataFloat = size/(1024*1024*1.0) ;
return[NSStringstringWithFormat:@"%.1fMB",aFloat];
}else{
CGFloataFloat = size/(1024*1024*1024*1.0) ;
return[NSStringstringWithFormat:@"%.1fG",aFloat];
}
}
通过以上代码就可以实现清除缓存的功能了,快来试试吧~
来源: 简书
很多app中都有清除缓存的功能,今天来说一下这种功能怎么操作,具体见如下代码:
首先一般清除缓存之前会有一个提示,是否清理缓存
#pragma mark -缓存处理
//清楚缓存调用
- (void)clearCacheAction {
UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"是否清理缓存"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
alert.tag=CLEARCACHE_ALERT_TAG;
[alertshow];
}
然后写提示的代理方法:
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(CLEARCACHE_ALERT_TAG== alertView.tag){
if(0== buttonIndex ){
}else{
[selfclearCache];
}
}
}
以下就是具体的清理缓存的方法了:
#pragma mark -
//清除缓存调用
- (void)clearCache {
[[[SDWebImageManagersharedManager]imageCache]clearDisk];
[[[SDWebImageManagersharedManager]imageCache]clearMemory];
[[CNToolsharedInstance]clearAllCache];
[selfpresentSuccessTips:@"缓存已清理"];
//修改显示数据
NSIndexPath*indexPath = [NSIndexPathindexPathForRow:0inSection:1];
SELFSettingDefaultCell*cell = [self.tableViewcellForRowAtIndexPath:indexPath];
cell.subTitle.text= [selfcalculateCacheSize];
}
显示出来的缓存大小是要计算的,计算方法如下:
//计算缓存大小
- (NSString*) calculateCacheSize {
NSIntegersize = [[SDImageCachesharedImageCache]getSize];
if(size<1024*1024*1024){//小于1G
CGFloataFloat = size/(1024*1024*1.0) ;
return[NSStringstringWithFormat:@"%.1fMB",aFloat];
}else{
CGFloataFloat = size/(1024*1024*1024*1.0) ;
return[NSStringstringWithFormat:@"%.1fG",aFloat];
}
}
通过以上代码就可以实现清除缓存的功能了,快来试试吧~
来源: 简书
0 0
- iOS中如何清除缓存?
- jsp中如何清除缓存
- Android中如何清除缓存
- iOS 设置中清除缓存功能
- C++中stringstream类如何清除缓存
- ios webview清除缓存。
- ios webview清除缓存
- iOS开发清除缓存
- ios webview清除缓存
- ios webview清除缓存
- ios webview清除缓存
- IOS清除缓存
- iOS清除缓存
- 清除ios的缓存
- iOS 清除缓存
- iOS 清除缓存
- iOS 清除缓存
- iOS清除缓存
- Linux学习之sed的使用
- JSP中文件的上传与下载示例
- LeetCode——17. Letter Combinations of a Phone Number
- Java IO流之打印流与标准流
- lasync命令模块实用工具cmdutils
- iOS中如何清除缓存?
- JQueryAjax操作
- PHP和Python中的引用机制
- 如何设置覆铜与不同网络的间隙
- 学习tf.sparse_to_dense函数(代码实现)
- AngularJS中filter过滤器的用法详解
- 解决 genymotion 联通本机服务器(apache为例)
- 第五讲、文本编辑器(vim/vi)
- hdu 1558 Segment set 并查集 叉积判断线段是否相交