【问题标题】:-[NSBundle pathForResource:ofType:inDirectory:] returns nil for localized resources-[NSBundle pathForResource:ofType:inDirectory:] 为本地化资源返回 nil
【发布时间】:2015-06-26 21:44:19
【问题描述】:

我有一个这样的捆绑结构:

bundle's root
------atlases
------------en.lproj
--------------------test-hd.plist
------------es.lproj
--------------------test-hd.plist

但是当我尝试使用此代码获取 test-hd.plist 以进行当前本地化时

[[NSBundle mainBundle] pathForResource:@"test-hd.plist" ofType:nil inDirectory:@"atlases"]

它总是返回 nil。我的错误在哪里?我该如何解决? 附言“atlases”文件夹被添加为文件夹引用,并且 test-hd.plist 始终可以通过直接路径[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"atlases/en.lproj/test-hd.plist"]

【问题讨论】:

    标签: ios objective-c cocoa cocoa-touch


    【解决方案1】:

    您的目录结构错误。 en.lproj等,应该包含一个名为atlases的目录,像这样:

    <bundle root>
    |-- en.lproj
    |---- atlases
    |------ test-hd.plist
    |-- es.lproj
    |---- atlases
    \------ test-hd.plist
    

    【讨论】:

    • 谢谢,它正在工作,但有什么方法可以让我的目录结构正常工作吗?
    • 而且似乎根据 Apple 的文档(-[pathForResource:ofType:inDirectory:] 讨论中的示例)它必须像我一开始所期望的那样工作...developer.apple.com/library/ios/documentation/Cocoa/Reference/…:
    • @SiarheiFedartsou:不,这就是NSBundle 搜索文件的方式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多