创建一个带有情节提要的自定义可可豆荚 [英] Creating a custom cocoa pod with a storyboard in it

查看:59
本文介绍了创建一个带有情节提要的自定义可可豆荚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个pod,并且在资源包中有一个故事板(已本地化)。

I am creating a pod, and in the resource bundle I have a storyboard (localised).

当我尝试实例化一个故事板时,发生了一个错误:在捆绑包NSBundle中找不到名为 MyStoryboard的故事板。代码如下所示:

When I try to instantiate a storyboard, an error occurred: Could not find a storyboard named 'MyStoryboard' in bundle NSBundle. The code look like this:

NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"MyBundle" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:bundle];

MyBundle结构如下:

MyBundle structure looks like this:

- MyBundle.bundle
  - Base.lproj
    - MyStoryboard.storyboard
  - es.lproj
    - MyStoryboard.strings

故事板可以首先包含在捆绑包中吗?

Can storyboard can be included in a bundle in the first place?

我还没有看到Pod包含故事板的示例。如果您知道分享其故事板的任何吊舱,也请告诉我。

I have not seen examples of Pod that includes storyboards. If you know of any pods that share their storyboard, let me know too.

推荐答案

有两点需要牢记。


  1. 您可以通过预定义的捆绑包添加pod资源,例如

  1. You add your pod resources via a predefined bundle like

s.resources = ["Resources/Pod.bundle"]


在这种情况下,捆绑包的内容将被复制到xcode项目中,而无需任何进一步处理。这意味着情节提要或Xib文件将不会被编译,并且在您的项目中将不可用。

in this case the content of your bundle will be copied to your xcode project without any "further processing". This means that storyboards or xib files will not be compiled and won't be available in your project.


  1. 您可以明确提及您的情节提要/ nib文件,例如

  1. You can explicitly mention your storyboard/nib files like

s.resources = ["Resources/**/*.storyboard"]


在这种情况下,情节提要将被编译并将在您的项目中可用。不利的一面(在撰写本文时)是您不能使用本地化的故事板,因为所有故事板都将在包的根位置进行处理和复制。因此,位于不同 .lproj 文件夹中的同名情节提要板将被覆盖。

In this case the storyboard will be compiled and will be available in your project. The downside of this (at the moment of this writing) is that you can not use localized storyboards, because all storyboards will be processed and copied at the root location of your bundle. So storyboards with the same name in different .lproj folders will be overwritten.

这篇关于创建一个带有情节提要的自定义可可豆荚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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