ios - 从文档文件夹中获取所有图像

标签 ios objective-c uiimageview

我有一些来自文件夹的图片。

现在,我想从文档文件夹中获取所有图像以在 UIImageView 中设置,并且 UIImageView 必须在 tableViewCell 中。

怎么做?

请帮帮我!

编辑:

enter image description here

最佳答案

试试这个..

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
}

关于ios - 从文档文件夹中获取所有图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30993011/

相关文章:

ios - 滚动时 Swift UICollectionViewCell 动画 View 随机空白

ios - 如何从 View Controller 中选择 Storyboard中的 UIImage

ios - SIGABRT 与编辑表 - IOS

ios - 如何在 iOS 编程中向视频文件添加和检索自定义元数据?

ios - 如何在透视中绘制图像?

objective-c - AF网络和下载速度限制

ios - UITextView 后面的 ImageView 未剪切到边界

ios - scrollToRowAtIndexPath 在 iOS 8 上无法正确滚动到底部

iphone - 以编程方式禁用 Alertview

iphone - Objective-C/iOS - 测试是否存在 C 函数?