NSBundle - (尚未加载)错误
我正在尝试获取与 NSLocalizedStringFromTableInBundle 一起使用的字符串文件表。
我正在使用这种方法:
+(NSBundle*)getBundleForLang:(NSString*)lang{
//get the path to the bundle
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"localizable" ofType:@"strings" inDirectory:nil forLocalization:lang];
NSLog(@"bundlePath = %@",bundlePath);
//load the bundle
NSBundle *langBundle = [[NSBundle alloc] initWithPath:[bundlePath stringByDeletingLastPathComponent]];
NSLog(@"langBundle = %@",langBundle);
return langBundle;
}
虽然它在模拟器上工作得很好,但当我尝试在 iPhone 设备上使用它时,我得到这个 NSLog:
2011-12-09 00:40:14.533 MyApp[12754:707] langBundle = NSBundle
</var/mobile/Applications/915E6BCB-EC44-4F1D-891B-EF68E2FA89C2/MyApp.app/he.lproj>
(not yet loaded)
Why isn't it returned and where is the Problem?
谢谢沙尼
I am trying to get a strings file table for use with NSLocalizedStringFromTableInBundle.
I am using this method:
+(NSBundle*)getBundleForLang:(NSString*)lang{
//get the path to the bundle
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"localizable" ofType:@"strings" inDirectory:nil forLocalization:lang];
NSLog(@"bundlePath = %@",bundlePath);
//load the bundle
NSBundle *langBundle = [[NSBundle alloc] initWithPath:[bundlePath stringByDeletingLastPathComponent]];
NSLog(@"langBundle = %@",langBundle);
return langBundle;
}
While it is working great on the simulator, when i try to use it on an iPhone device i get this NSLog:
2011-12-09 00:40:14.533 MyApp[12754:707] langBundle = NSBundle
</var/mobile/Applications/915E6BCB-EC44-4F1D-891B-EF68E2FA89C2/MyApp.app/he.lproj>
(not yet loaded)
Why isn't it loaded and where is the problem?
Thanks
Shani
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查文件路径的大小写。
模拟器(默认情况下)不区分大小写,而设备则区分大小写。
这可能会导致模拟器成功找到该文件,但设备却失败。
Check the case of your file paths.
The simulator (by default) is not case sensitive, whereas the device is.
This could cause the simulator to successfully find the file, but the device to fail.
这不是一个错误。字符串捆绑包(例如 en.lproj)不包含可执行文件。当您尝试
[bundle loadAndReturnError:]
时,它将失败,并且loadAndReturnError:
的文档 会告诉你原因。It's not an error. Strings bundle, such as en.lproj, does not include executable file. When you try to
[bundle loadAndReturnError:]
, it will fail, andloadAndReturnError:
's document will tell you why.确保捆绑包包含捆绑包标识符。
如果没有,尽管路径可用,但无法从那里加载资源。
Make sure the bundle contains a bundle identifier.
If it does not, despite the path is available, the resources can't load from there.