0

I have some images from document folder.

Now, I want get all images from document folder to set in UIImageView and UIImageView have to inside in tableViewCell.

How to do it?

Please help me!

Edited:

enter image description here

  • Does the images are inside a folder? Maybe this [question](http://stackoverflow.com/questions/8635909/loading-an-image-from-documents-directory) can help. – NSPunk Jun 23 '15 at 02:56

1 Answers1

4

Try this..

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *myPath = [paths objectAtIndex:0];
// if you save fies in a folder
//myPath = [myPath stringByAppendingPathComponent:@"folder_name"];

NSFileManager *fileManager = [NSFileManager defaultManager];
// all files in the path
NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:myPath error:nil];

// filter image files
NSMutableArray *subpredicates = [NSMutableArray array];
[subpredicates addObject:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.png'"]];
[subpredicates addObject:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.jpg'"]];
NSPredicate *filter = [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates];

NSArray *onlyImages = [directoryContents filteredArrayUsingPredicate:filter];

for (int i = 0; i < onlyImages.count; i++) {
    NSString *imagePath = [myPath stringByAppendingPathComponent:[onlyImages objectAtIndex:i]];
    UIImage *tempImage = [UIImage imageWithContentsOfFile:imagePath];
    // do something you want
}
Reming Hsu
  • 2,215
  • 15
  • 18