【发布时间】:2011-10-21 09:45:32
【问题描述】:
我正在尝试像这样加载图像的字节:
NSURL *img = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"img" ofType:@"png"] isDirectory:NO];
NSString * test = [NSString stringWithContentsOfFile:[img absoluteString] encoding:NSASCIIStringEncoding error:&err];
但我总是收到以下错误:
Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn\u2019t be completed.
(Cocoa error 260.)" UserInfo=0xc02abf0
{NSFilePath=file://localhost/Users/admin/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/C55551DB-152A-43D6-A1E0-9845105709D6/myApp.app/img.png,
NSUnderlyingError=0xc02ccc0 "The operation couldn\u2019t be completed. Folder or file does not exist"}
但是文件确实存在,如果我将 NSFilePath 复制/粘贴到浏览器中,它会找到图像。有什么问题?
【问题讨论】:
标签: iphone nsstring nsurl nsbundle