Yad*_*esh 42 xcode objective-c filepath nsbundle ios
我paylines.txt
在名为的文件夹中添加了一个文件,该文件TextFiles
位于Resources
Xcode中我的iOS项目的文件夹中.
这是我用来访问文件的代码:
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"paylines" ofType:@"txt" inDirectory:@"TextFiles"];
NSLog(@"\n\nthe string %@",filePath);
Run Code Online (Sandbox Code Playgroud)
代码打印:
2011-06-07 14:47:16.251 slots2[708:207]
the string (null)
Run Code Online (Sandbox Code Playgroud)
Nee*_*rma 163
我也遇到了同样的问题.我找到的解决方案是(在xcode 4.x中):
转至:目标 - >"构建阶段" - >"复制捆绑资源"然后在此处添加该特定文件. 如果已添加该文件,请将其删除并重新添加.
清理项目并运行.有用. :)
Raj*_*071 10
试试这个,它为我工作.
NSString *str = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"paylines.txt"];
Run Code Online (Sandbox Code Playgroud)
对于模拟器
NSURL *rtfUrl = [[NSBundle mainBundle] URLForResource:@"paylines" withExtension:@".txt"];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
103289 次 |
最近记录: |