使用[NSBundle mainBundle] pathForResource:ofType:inDirectory访问文件: [英] accessing a file using [NSBundle mainBundle] pathForResource: ofType:inDirectory:

查看:585
本文介绍了使用[NSBundle mainBundle] pathForResource:ofType:inDirectory访问文件:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为 TextFiles 的文件夹中添加了 paylines.txt 文件,该文件位于<$ c $内c>资源我在Xcode中的iOS项目的文件夹。

I have a file paylines.txt added inside the folder named TextFiles which resides inside the Resources folder of my iOS project in Xcode.

这是我用来访问该文件的代码:

This is the code I use to access the file:

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)


推荐答案

我发现了我提交的错误我正在为项目添加一个组而不是添加真正的目录更多< a href =http://www.iphonedevsdk.com/forum/iphone-sdk-development/31256-nsbundle-pathforresource-indirectory-gives-nil.html\"rel =noreferrer>说明

well i found out the mistake i was committing i was adding a group to the project instead of adding real directory for more instructions

这篇关于使用[NSBundle mainBundle] pathForResource:ofType:inDirectory访问文件:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆