如何从我的iPhone应用程序文档目录中选择所有图像

如何从我的iPhone应用程序文档目录中选择所有图像,iphone,ios,objective-c,Iphone,Ios,Objective C,我有一个文件夹,里面有一堆图片。我想将所有图像的名称添加到一个数组中。这些图像位于应用程序“我的文档”中的文件夹中。参见屏幕截图 我知道如果我想得到这些图像中的一个,我会使用下面的代码 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0];

我有一个文件夹,里面有一堆图片。我想将所有图像的名称添加到一个数组中。这些图像位于应用程序“我的文档”中的文件夹中。参见屏幕截图

我知道如果我想得到这些图像中的一个,我会使用下面的代码

NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths objectAtIndex:0];
NSString  *filePath = [NSString stringWithFormat:@"%@/POIs/%@", documentsDirectory,image];
是否可以选择文件夹中的所有文件?如果是,是否也可以选择文件名并将其添加到数组中

谢谢

请尝试以下内容:

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    library = [path objectAtIndex:0];
    fileArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:library error:nil];
    NSLog(@"fileArray...%@",fileArray);



 for(int i = 0;i<fileArray.count;i++)
    {
        id arrayElement = [fileArray  objectAtIndex:i];
     if ([arrayElement rangeOfString:@".png"].location !=NSNotFound)
        {

        [imagelist addObject:arrayElement];
        arrayToLoad = [[NSMutableArray alloc]initWithArray:imagelist copyItems:TRUE];
        }
}
NSArray*path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
库=[path objectAtIndex:0];
fileArray=[[NSFileManager defaultManager]目录目录路径:库错误:nil];
NSLog(@“fileArray…%@”,fileArray);

对于(int i=0;i获取POS文件夹的文件路径:

NSString  *filePath = [NSString stringWithFormat:@"%@/POIs", documentsDirectory];
然后做:

NSArray *files = [fileManager contentsOfDirectoryAtPath:filePath 
                                                  error:nil];
未测试代码

您可以这样做:

NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] error:NULL];
要设置图像,请执行以下操作:

[imgView setImage:[UIImage imageWithContentsOfFile:"Your complete path"]];