在tableview中显示图像

时间:2011-11-24 06:24:38

标签: objective-c xcode image tableview

我没有显示任何图像,只显示文件名。

目前即时使用此代码:

NSString *filePath = [[self documentsPath] stringByAppendingPathComponent:@""];

NSFileManager *imagesFileManager = [NSFileManager defaultManager];


imagesArr = [[imagesFileManager contentsOfDirectoryAtPath:filePath error:nil]filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.jpg'"]];


arryList = [[NSMutableArray alloc] initWithArray:[imagesArr copy]];//display text
imagesList = [[NSMutableArray alloc]init];//display image

for (NSString *anImage in arryList) {
    anImage = [NSString stringWithFormat:@"Documents/%@",anImage];
    [imagesList addObject:anImage];

}

1 个答案:

答案 0 :(得分:2)

for循环中,您只是将文件路径添加到数组而不是UIImage。

更改for循环,如下所示:

NSString *docPath = [self documentsPath];

for (NSString *anImagePath in arryList) {
    anImagePath = [NSString stringWithFormat:@"%@/%@",docPath,anImagePath];
    UIImage *image = [UIImage imageWithContentsOfFile:anImagePath];
    if ( image )
      [imagesList addObject:image];
}