English 中文(简体)
图像与 Contents ofFile - 为什么不接受 ios 中的路径?
原标题:imageWithContentsOfFile - why does not accept path in ios?

我在这里迷路了。 我尝试使用这个方法来初始化一个 UIIMage 对象。 我知道它看文件目录等等,而不是缓存...

I provide respective URLs or paths but the object is always nil. The method is never succesful. Is it because my paths always contain the file prefix at the beginning? Like this?

file:// .somedir/somedir/etc.../fieldname.jpg /fieldname.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];

然后构建路径字符串。

最佳回答

这个

[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];
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签