0

我在这里迷路了。我尝试使用该方法初始化 UIImage 对象。我知道它在文档目录等中查找并且不缓存...

我提供了相应的 URL 或路径,但对象始终为零。该方法永远不会成功。是因为我的路径总是在开头包含文件前缀吗?像这样?

文件:// .somedir/somedir/etc.../filename.jpg

我通过使用此调用获取 docs 目录来创建路径

//get the documents directory path
NSURL *docsPath = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

// create the full image local path 
NSString *imageLocalPath = [NSString stringWithFormat:@"%@%u.jpg", docsPath, indexPath.row + 1];

然后构造路径字符串。

4

1 回答 1

1

[NSString stringWithFormat:@"%@", docsPath];

真的是这个

[NSString stringWithFormat:@"%@", [docsPath description]];

这根本不是你想要的。

尝试这样的事情: -

NSURL *docsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *fileName = [NSString stringWithFormat:@"%u.jpg", indexPath.row+1];
NSString *filePath = [[docsURL path] stringByAppendingPathComponent:fileName];
于 2012-05-24T16:19:52.620 回答