在表格视图中显示图像

发布于 2024-12-17 18:40:20 字数 671 浏览 0 评论 0原文

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

目前我使用这个代码:

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];

}

I didnt get any images displayed, only the filename is shown.

Currently im using this codes:

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];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半岛未凉 2024-12-24 18:40:21

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];
}

In the for loop , you are just adding the file path to the array instead of UIImage.

Change the for loop as follows:

NSString *docPath = [self documentsPath];

for (NSString *anImagePath in arryList) {
    anImagePath = [NSString stringWithFormat:@"%@/%@",docPath,anImagePath];
    UIImage *image = [UIImage imageWithContentsOfFile:anImagePath];
    if ( image )
      [imagesList addObject:image];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文