【问题标题】:Files Deleting from Table View but not from Document Directory by using Swipe Gesture使用滑动手势从表格视图中删除文件而不是从文档目录中删除文件
【发布时间】:2015-03-09 18:11:16
【问题描述】:
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];
    }

有什么建议吗?

【问题讨论】:

  • 你的文件路径即将到来吗? nslog 找出来
  • 看来您的 filePath 不正确。 NSError *error = nil;并将 ist 作为错误传递:&error;并使用 NSLog(@"error: %@",error); 检查输出
  • 是的。 ifpath 错误如何在表格视图中列出歌曲....
  • 我用来列出歌曲的相同路径.....localSongs=[[NSMutableArray alloc]init]; NSArray * 路径 = NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory, NSUserDomainMask, YES);文档目录 = [路径 objectAtIndex:0]; NSDirectoryEnumerator *de = [[NSFileManager defaultManager] enumeratorAtPath:documentsDirectory] ​​;

标签: iphone ios document swipe gesture


【解决方案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];

【讨论】:

  • 我不想删除单个文件。我想通过在文档目录中的滑动手势和文档目录中的子文件夹一一删除多个文件...请帮助解决它
  • 老兄它不工作.... localSongs=[[NSMutableArray alloc]init]; NSArray * 路径 = NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory, NSUserDomainMask, YES);文档目录 = [路径 objectAtIndex:0]; NSDirectoryEnumerator *de = [[NSFileManager defaultManager] enumeratorAtPath:documentsDirectory] ​​; // 我通过上面的方法在文档目录和其中的子文件夹中获取我的本地歌曲...
  • 检查你的文件名是否正确?
  • 它会删除文档目录中的所有文件,包括 sqlite 文件,但我想通过滑动手势删除表格视图中列出的特定文件.....
  • 当您滑动任何单元格时,获取包含在滑动单元格中的文件名...例如 NSString *fileName = [myArray objectAtIndex:indexPathe.row];... 在这里您可以从中获取文件名刷过的细胞。并在我的代码中使用这个名字..谢谢:)
猜你喜欢
  • 2023-04-03
  • 2012-03-05
  • 2011-08-06
  • 2013-02-07
  • 2011-08-14
  • 1970-01-01
  • 1970-01-01
  • 2012-12-18
  • 1970-01-01
相关资源
最近更新 更多