如何为 iPhone 创建仅资源包
我们正在尝试以特定语言的捆绑包形式提供我们的笔尖。由于几个不同的原因,这会对我们有所帮助。
我的问题是关于设置仅资源包。
- 当我通过“New Project - Framework &”在 xcode 中添加新包时Library - Bundle”菜单 xcode 将添加一个新的 xcodeproj 文件。这是正确的吗?我认为捆绑只是一个带有 .bundle 扩展名的目录。
- 如果我只想在我的包中包含 nib 文件,我还需要可执行文件和 info.plist 文件吗?
到目前为止,我已经手动创建了一个包目录并添加了 nib 文件。我可以使用
NSBundle bundleWithPath
不确定它是否已正确加载来访问它,但bundleWithPath方法不会返回nil。
但是当我尝试从捆绑包中打开 nib 文件时,出现以下错误:
* 由于未捕获的异常而终止应用程序 'NSInternalInco nsistencyException',原因:'无法加载 NIB 捆绑包:'NSBundle (尚未加载)',名称为“Nib”
我已将捆绑包添加到“复制捆绑包资源”中。
感谢您提供任何信息。我确信我让这件事变得比应有的更加困难。
编辑:我回去进行测试,添加了下面的行来查找 xib 而不是笔尖。它适用于 xib,但不适用于 nib。我认为这意味着 xib 可能没有被编译。
[languageBundle pathForResource:@"TestNib" ofType:@"xib"];
We are experimenting with delivering our nibs in language specific bundles. For a couple of different reasons this would help us out.
My questions are around setting up a resource only bundle.
- When I add a new bundle in xcode through the “New Project - Framework & Library - Bundle” menu xcode will add a new xcodeproj file. Is this correct? I thought a bundle was just a directory with a .bundle extension.
- If I want to only have nib files in my bundle do I still need an executable file and a info.plist file?
So far I have manually created a bundle directory and added nib files. I and can access it with
NSBundle bundleWithPath
Not sure if it's loaded correctly, but the bundleWithPath method does not return nil.
But when I try to open a nib file from the bundle I get the following error:
* Terminating app due to uncaught exception
'NSInternalInco nsistencyException', reason: 'Could not load NIB in
bundle: 'NSBundle
(not yet loaded)' with name 'Nib''
And I have added the bundle to "Copy Bundle Resources".
Thanks for any info. I'm sure I'm making this harder than it should be.
EDIT: I went back and for a test added the line below to look for the xib instead of the nib. It works for xib but not for nib. I think this means that that the xib maybe is not getting compiled.
[languageBundle pathForResource:@"TestNib" ofType:@"xib"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不正确的。您应该向当前项目添加新目标,而不是创建新项目。
您不需要可执行文件,但您可能需要一个 Info.plist 才能使其成为一个适当的捆绑包(可能不是绝对必要的,但拥有一个也不会有什么坏处)。
现在,您将 nib 文件放在捆绑包中而不是放在 .lproj 目录中是否有原因?此外,您需要先展示一些实际代码,然后我们才能提供进一步的帮助。
No, this is not correct. You should add a new target to your current project instead of creating a new project.
You don't need an executable, but you will probably need an Info.plist for it to be a proper bundle (it might not be strictly necessary, but it won't hurt to have one).
Now, is there a reason you're putting your nib files in a bundle instead of in .lproj directories? Also, you'll need to show some of your actual code before we can offer further help.