为什么 Apple 的这个示例代码不起作用?
我正在尝试查找名为“file1.jpg”的文件的完整路径,
我已验证它位于应用程序包中,但是当我运行此代码时:
NSBundle* myBundle = [NSBundle mainBundle];
NSString* path = [myBundle pathForResource:@"file1" ofType:@"jpg"];
“路径”没有我期望的路径/文件。
这是直接来自 Apple 文档的代码。
我做错了什么?
I am trying to find the full path for a file called 'file1.jpg'
I have verified that it is in the app bundle and yet when I run this code:
NSBundle* myBundle = [NSBundle mainBundle];
NSString* path = [myBundle pathForResource:@"file1" ofType:@"jpg"];
'path' doesn't have the path/file I'm expecting.
This is code directly from the Apple documentation.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果路径为零,则 file1.jpg 在您的应用程序包中不存在。确保它在您的项目中并且设置为包含在您当前的目标中。另外,它区分大小写,因此请确保文件的名称确实是
file1.jpg
,而不是file1.JPG
或file1.jpeg
或某物。If path is nil then file1.jpg does not exist in your application bundle. Make sure that it is in your project and that it is set to be included in your current target. Also, it is case sensitive, so make sure that the file is really named
file1.jpg
and notfile1.JPG
orfile1.jpeg
or something.如果您在使用调试器时构建 DEBUG 版本而不是 RELEASE 版本,它也会有所帮助:)
It also helps if you are building the DEBUG version and not the RELEASE version when using the debugger :)