-1

I'm new on iPhone Dev. I need to show all image from a particular folder on gridview but I don't know how to.

Advice me please.Thank you Ps.sorry for bad english

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
miniplayground
  • 301
  • 2
  • 12

2 Answers2

4

Im not sure about the grid view part. But this will help you list the images.

    NSString *documents = [@"~/Documents/gallery" stringByExpandingTildeInPath];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSDirectoryEnumerator *direnum = [fileManager enumeratorAtPath:documents];
    NSError *error;
    NSString *tString;
    while ((tString = [direnum nextObject] ))
    {
        if ([tString hasSuffix:@".jpg"]) 
        {
            NSString *fileAbsPath = [NSString stringWithFormat:@"%@/%@",documents,tString];
            //Do something with the file
        }
    }
Craig White
  • 13,492
  • 4
  • 23
  • 36
0

This is how you will get all files from a particular folder. You can replace NSCachesDirectory with NSDocumentDirectory.

- (NSArray *)getAllFilesfromAFolder:(NSString *)folderName
{
    NSString *stringPath = nil;
    if(folderName)
        stringPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:folderName];
    else
        stringPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0];

    NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:stringPath  error:nil];
    return filePathsArray;
}
Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75