相关疑难解决方法(0)

NSBundle pathForResource为NULL

我正在使用xcode和objc创建一个简单的应用程序,我需要从文件加载NSDictionary,但我无法使用NSBundle获取该文件的路径:

NSString *l = [[NSBundle mainBundle] pathForResource:@"LoginStatuses" ofType:@"plist"];
NSLog(@"%@", l);
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我得到了这个:

2010-10-16 10:42:42.42样本[5226:a0f](null)

我不知道为什么.

我创建了一个名为Resources的组,在那里我添加了LogingStatuses.plist: 水库

xcode objective-c nsbundle

38
推荐指数
4
解决办法
4万
查看次数

NSBundle pathForResource返回带有子目录的nil

例如,我的应用程序中有一堆目录和文件images/misc/mainmenu_background..我在"iPad模拟器3.2"中运行以下代码:

NSString *images = [[NSBundle mainBundle] pathForResource:@"images" ofType:nil];
NSString *images_misc = [[NSBundle mainBundle] pathForResource:@"images/misc" ofType:nil];
NSString *images_misc_file = [[NSBundle mainBundle] pathForResource:@"images/misc/mainmenu_background.png" ofType:nil];
Run Code Online (Sandbox Code Playgroud)

在此调用之后,images包含路径/Users/wic/Library/Application Support/iPhone Simulator/3.2/Applications/8F67150B-71E6-4735-8CC6-38B3CE6D3568/Foo.app/images.

但是images_misc,images_misc_filenil.仔细检查我的文件系统以检查文件是否存在:

$ ls -l "/Users/wic/Library/Application Support/iPhone Simulator/3.2/Applications/8F67150B-71E6-4735-8CC6-38B3CE6D3568/Foo.app/images/misc/mainmenu_background.png"
-rw-rw-rw-  1 wic  staff  30307 16 Feb 21:09 /Users/wic/Library/Application Support/iPhone Simulator/3.2/Applications/8F67150B-71E6-4735-8CC6-38B3CE6D3568/Foo.app/images/misc/mainmenu_background.png
Run Code Online (Sandbox Code Playgroud)

显然文件就在那里.

如果我切换到"iPad模拟器4.0",或任何其他模拟器版本的一切都按预期工作.

我的设置有问题,或者NSBundle在iPad 3.2中这是正确的行为吗?不幸的是,我没有真正的物理iPad来测试它.

xcode nsbundle ios-simulator

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

nsbundle ×2

xcode ×2

ios-simulator ×1

objective-c ×1