我正在尝试从目录中获取 .caf 文件,然后将它们放入 UIPickerView 中,以便在点击每一行时播放它们。
到目前为止,我有这段代码,但不知道如何将文件放入数组中。
NSString *extension = @"caf";
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentsDirectory14 = [documentsDirectory stringByAppendingPathComponent:@"/Family"];
NSArray *contents = [fileManager contentsOfDirectoryAtPath:documentsDirectory14 error:&error];
NSMutableArray *cafFiles = [NSMutableArray arrayWithCapacity: [contents count]];
NSString *filename;
for (filename in contents)
NSLog(@"filename;%@",filename);
{
if ([[filename pathExtension] isEqualToString:extension])
{
[cafFiles addObject: [NSMutableArray arrayWithContentsOfFile:[documentsDirectory14 stringByAppendingPathComponent:filename]]];
}
}
NSLog(@"jpegFiles;%@",cafFiles );
covers= [NSMutableArray arrayWithArray:cafFiles];{
for (filename in cafFiles);
}
NSLog(@"%@", covers);
有人可以帮我吗?
如果我使用封面作为它的数组,这会将文件的名称放在选择器视图中吗?