iOS清除緩衝,ios緩衝

來源:互聯網
上載者:User

iOS清除緩衝,ios緩衝

-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath

{

staticNSString*identifier=@"myCell";

    UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:identifier];

    

  if(cell==nil){

        cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleValue1reuseIdentifier:identifier];

    }

cell.textLabel.text=@"清除緩衝";

  NSString*bundleId=[[[NSBundlemainBundle]infoDictionary]objectForKey:@"CFBundleIdentifier"];

    NSArray*paths=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);

    NSString*path=[[pathsobjectAtIndex:0]stringByAppendingPathComponent:bundleId];

    CGFloatsize=[selffolderSizeAtPath:path];

    if(size> 10)

    {

       if(size< 1000)

      {

          cell.detailTextLabel.text=[NSStringstringWithFormat:@"%.0fB",size];

       } else if(size< 1000* 1000){

          cell.detailTextLabel.text=[NSStringstringWithFormat:@"%.2fKB",size/ 1000];

       }else{

          cell.detailTextLabel.text=[NSStringstringWithFormat:@"%.2fMB",size/ 1000 / 1000];

       }

    }else{

      cell.detailTextLabel.text=@"";

    }

}



-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath

{

NSString*bundleId=[[[NSBundlemainBundle]infoDictionary]objectForKey:@"CFBundleIdentifier"];

  NSArray*paths=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);

    NSString*path=[[pathsobjectAtIndex:0]stringByAppendingPathComponent:bundleId];

    [[NSFileManagerdefaultManager]removeItemAtPath:patherror:nil];

  

    UIAlertView*alertCache=[[UIAlertViewalloc]initWithTitle:nilmessage:@"緩衝清楚成功"delegate:nilcancelButtonTitle:@"確定"otherButtonTitles:nil,nil];

    [alertCacheshow];

    [tableViewreloadData];

}


計算檔案大小

#pragmamark-getfilesize

- (longlong)fileSizeAtPath:(NSString*)filePath{

    NSFileManager*manager=[NSFileManagerdefaultManager];

    if([managerfileExistsAtPath:filePath]){

        return[[managerattributesOfItemAtPath:filePatherror:nil]fileSize];

    }

    return 0;

}

- (float)folderSizeAtPath:(NSString*)folderPath{

    NSFileManager*manager=[NSFileManagerdefaultManager];

    if(![managerfileExistsAtPath:folderPath])return 0;

    NSEnumerator*childFilesEnumerator= [[managersubpathsAtPath:folderPath]objectEnumerator];

    NSString*fileName;

    longlongfolderSize= 0;

    while((fileName=[childFilesEnumeratornextObject])!=nil){

        NSString*fileAbsolutePath=[folderPathstringByAppendingPathComponent:fileName];

        folderSize+=[selffileSizeAtPath:fileAbsolutePath];

    }

    returnfolderSize;

}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.