开发者社区> 问答> 正文

关于滑动手势从tableView删除文件

if (editingStyle == UITableViewCellEditingStyleDelete){
         NSFileManager *fileManager = [[NSFileManager alloc]init];       
         NSString *filePath = [documentsDirectory
         stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ ",[self->localSongs objectAtIndex:indexPath.row]]];        
        [fileManager removeItemAtPath:filePath error:nil]; 
        [self->localSongs removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView reloadData];
    }

要实现使用滑动手势从TableView删除文件,不从文件目录中

展开
收起
爵霸 2016-03-17 13:38:31 2059 0
1 条回答
写回答
取消 提交回答
  • NSString *imageName = @"name of your file"
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
    
        [fileManager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:imageName] error:nil];
    2019-07-17 19:05:13
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载