【发布时间】:2015-06-23 02:45:14
【问题描述】:
我有一些来自文件夹的图片。
现在,我想从文档文件夹中获取所有图像以在 UIImageView 中设置,并且 UIImageView 必须在 tableViewCell 中。
怎么做?
请帮帮我!
已编辑:
【问题讨论】:
-
图片是否在文件夹中?也许这个question 可以提供帮助。
标签: ios objective-c uiimageview
我有一些来自文件夹的图片。
现在,我想从文档文件夹中获取所有图像以在 UIImageView 中设置,并且 UIImageView 必须在 tableViewCell 中。
怎么做?
请帮帮我!
已编辑:
【问题讨论】:
标签: ios objective-c uiimageview
试试这个..
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
}
【讨论】: