iphone - 如何从Documents文件夹中加载动态保存的图像?

标签 iphone

我在将 iPhone 应用程序的 Documents 文件夹中的图像加载到 tableView 时遇到问题。

在一个单独的请求中,我在服务器上检查所有可用图像并将它们下载到“文档”下的“图像”文件夹中。我非常确定图像已正确保存。

NSString *filePath = [imagesFolderPath stringByAppendingPathComponent:imageFileName];
    [urlData writeToFile:filePath atomically:NO];
NSLog(@"Saved to file: %@", filePath);

2010-01-22 17:07:27.307 Foo[2102:207] Saved to file: /Users/Hoang/Library/Application Support/iPhone Simulator/User/Applications/6133A161-F9DC-4C92-8AE6-5651022EAA94/Documents/images/86_2.png

[NSBundle mainBundle] 不适合加载图像,因为在运行时,应用程序会尝试连接到服务器来下载图像,它们不是静态的。

但是从 Documents/images 文件夹加载图像不会在 TableView 上提供图像。

static NSString *CellIdentifier = @"CellCategory";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
UIImageView *imageView = cell.imageView;

MenuItem *item = (MenuItem *) [arrayMenuItems objectAtIndex:indexPath.row];
cell.textLabel.text = item.descrizione;


NSString *strImagePath = [[imagesFolderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%d_%d", item.idItem, item.idNode]] stringByAppendingPathExtension:@"png"];  
NSLog(@"strImagePath: %@", strImagePath);
imageView.image = [[UIImage imageWithContentsOfFile:strImagePath] autorelease];



2010-01-22 17:07:42.842 Foo[2102:207] strImagePath: /Users/Hoang/Library/Application Support/iPhone Simulator/User/Applications/6133A161-F9DC-4C92-8AE6-5651022EAA94/Documents/images/86_2.png

有人遇到同样的问题吗?

我在 stackoverflow 上查了一下,但没有成功。

提前致谢。

最佳答案

我刚刚将图像从应用程序的文档文件夹加载到 UITableViewCell 时遇到了同样的问题。这有效:

[UIImage imageWithContentsOfFile:fullPath];

关于iphone - 如何从Documents文件夹中加载动态保存的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2118709/

相关文章:

ios - 是否可以使用 OCMock 来模拟类方法和协议(protocol)?

iphone - 当我按下计算器中的任何数字按钮时,iOS 模拟器会生成错误

iOS 根据条件为 UIView 交换类

ios - 尺寸等级专门用于纵向 3.5 英寸(iPhone 4S)Xcode 6?

ios - 在初始屏幕上播放视频文件

iphone - 在 TableView 中同时启用多编辑和单编辑样式

ios - WKInterfaceTable 检测选择了哪一行

ios - 如何使用 Collection View 单元格swift ios实现 GridView

iphone - 同步 NSMutable 数组以进行线程处理

iphone - 在 iOS 中集成 Facebook SDK