iphone 利用数组遍历某一文件夹中的图片

1,使用数组遍历某一文件夹中的图片,代码如下:

  NSFileManager *fileManager = [NSFileManager defaultManager];  

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"%d",[paths count]);
NSError *error = nil;
NSArray *fileList = [[NSArray alloc] init];
NSMutableArray *filePath = [NSMutableArray arrayWithCapacity:100 ];
NSMutableArray *imgArray = [NSMutableArray arrayWithCapacity:200];
//NSArray *filePath = [[NSArray alloc] init];
fileList = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:&error];
for (NSString *file in fileList) {
NSLog(@"fileName is :%@",file);
[filePath addObject:[documentsDirectory stringByAppendingPathComponent:file]];
}
for (int i = 0; i<[fileList count]; i++) {
UIImage *temp = [UIImage imageWithContentsOfFile:[filePath objectAtIndex:i]];
[imgArray addObject:temp];
[imgView1 setImage:[imgArray objectAtIndex:0]];
[imgView2 setImage:[imgArray objectAtIndex:1]];
[imgView3 setImage:[imgArray objectAtIndex:2]];
[imgView4 setImage:[imgArray objectAtIndex:3]];
[imgView5 setImage:[imgArray objectAtIndex:4]];
[imgView6 setImage:[imgArray objectAtIndex:5]];
[imgView7 setImage:[imgArray objectAtIndex:6]];
[imgView8 setImage:[imgArray objectAtIndex:7]];
[imgView9 setImage:[imgArray objectAtIndex:8]];
posted on 2011-12-07 13:41  wtq  阅读(442)  评论(0编辑  收藏  举报