我在名为 TextFiles
的文件夹中添加了一个文件 paylines.txt
,该文件夹位于 Xcode 中我的 iOS 项目的 Resources
文件夹中。
这是我用来访问文件的代码:
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"paylines" ofType:@"txt" inDirectory:@"TextFiles"];
NSLog(@"\n\nthe string %@",filePath);
代码打印:
2011-06-07 14:47:16.251 slots2[708:207]
the string (null)
最佳答案
我也遇到了同样的问题。 我找到的解决方案是(在 xcode 4.x 中):
转到:目标 -> “构建阶段” -> “复制捆绑资源” 然后在此处添加该特定文件。 如果该文件已添加,请将其删除并重新添加。
清理项目并运行。它有效。 :)
关于objective-c - 使用 [NSBundle mainBundle] pathForResource : ofType:inDirectory: 访问文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6263289/