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

Hoa*_*ham 2 iphone

我有问题从iPhone应用程序的Documents文件夹中加载图像到tableView.

在单独的请求中,我在服务器上检查所有可用的图像,并将它们下载到Documents下的"images"文件夹中.我很确定图像是否正确保存.

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
Run Code Online (Sandbox Code Playgroud)

[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
Run Code Online (Sandbox Code Playgroud)

有没有人有同样的问题?

我在stackoverflow中环顾四周但没有成功.

提前致谢.

Tom*_*Tom 5

我在将应用程序的Documents文件夹中的图像加载到UITableViewCell时遇到了同样的问题.这有效:

[UIImage imageWithContentsOfFile:fullPath];
Run Code Online (Sandbox Code Playgroud)