iphone Documents文件中保存的图片如何读取并显示?
1:原文摘自:http://www.cocoachina.com/bbs/read.php?tid=32931
我在Documents文件中建了一个文件夹fileName, 文件夹保存的有一张图片.我想读出来并在UIImageView中显示,这如何实现呢?下面是我写的代码,不知道哪出问题了??
#import <UIKit/UIKit.h>
@interface UIView{
UIImageView *image;
}
@property (nonatomic, retain) IBOutlet UIImageView *image;
@end
@implementation
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"fileName"];
NSArray *array = [fileManager directoryContentsAtPath:filePath];
for (int i = 0; i<[array count]; i++)
{
NSString *s = [array objectAtIndex:i];
UIImage *image1 = [UIImage imageNamed:s];
[image setImage:image1];
}