2012-05-24 38 views
0

我迷失在这里。我尝试用该方法初始化UIImage对象。我明白,它看起来在文件目录等,并不缓存...imageWithContentsOfFile - 为什么不接受ios路径?

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

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

我通过获取文档目录使用该调用

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

,然后构建创建路径路径字符串。

回答

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]; 
相关问题