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
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
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
}
}
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;
}