Reputation: 23
Hello I can get a UITableView
to display the file name of images stored in the documents folder. Is there any way to get a UICollectionView
to display these images in a collection view?
Thanks Liam
Upvotes: 0
Views: 1545
Reputation: 762
// fetch all the files from the documents directory.
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
library = [path objectAtIndex:0];
fileArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:library error:nil];
NSArray *imagelist = [[NSArray alloc] init];
// filter the images from all the files.
for(int i = 0;i<fileArray.count;i++)
{
id object = [fileArray objectAtIndex:i];
if ([object rangeOfString:@".png"].location !=NSNotFound)
{
[imagelist addObject:object];
}
}
then create an instance of collection view and use following UICollectionView datasource to add the item in the collection view,
Upvotes: 0
Reputation: 4235
Yes you can. Here is a UICollectionView Programming Guide.
UICollectionView
collectionView:cellForRowAtIndexPath:
return cell with image using +imageNamed:
method.Remember to create custom cell with UIImageView
inside, create outlet.
Here is Tutorial which should help you.
Upvotes: 2