【问题标题】:Reading files from Documents directory using xcode使用 xcode 从 Documents 目录中读取文件
【发布时间】:2012-03-16 06:23:49
【问题描述】:

关于我自己的问题, UITable is not getting populated with NSMutableArray 在这里,我将所有文件名放入一个表中。这些文件存储在“资源”文件夹中。现在我需要从存储在 ios 模拟器的文档文件夹中的子文件夹中的文件中填充同一张表。 早些时候我用下面的代码做到了这一点

files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
     [[NSBundle mainBundle] bundlePath] error:nil];
search_results_array = [files filteredArrayUsingPredicate:
                    [NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] 'h'"]];

这里的 files 和 search_results_array 都是数组。现在阅读不是来自资源。我该如何编辑它?请任何人帮忙。

【问题讨论】:

    标签: xcode nsarray nspredicate nsbundle


    【解决方案1】:

    使用以下内容:

    NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //Library directory is not accessible via iTunes, Document directory is
        NSString *docDirectory = [paths objectAtIndex:0]; //2
        path = [docDirectory stringByAppendingPathComponent:yourString]; //3
        files = [[NSDictionary alloc] initWithContentsOfFile: path];
    

    假设 files 是一个 NSDictionary。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      相关资源
      最近更新 更多