xcode 创建一个带有故事板的自定义可可豆荚
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23292306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a custom cocoa pod with a storyboard in it
提问by samwize
I am creating a pod, and in the resource bundle I have a storyboard (localised).
我正在创建一个 pod,在资源包中我有一个故事板(本地化)。
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:
当我尝试实例化故事板时,发生错误:Could not find a storyboard named 'MyStoryboard' in bundle NSBundle
. 代码如下所示:
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"MyBundle" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:bundle];
MyBundle structure looks like this:
MyBundle 结构如下所示:
- MyBundle.bundle
- Base.lproj
- MyStoryboard.storyboard
- es.lproj
- MyStoryboard.strings
Can storyboard can be included in a bundle in the first place?
故事板可以首先包含在包中吗?
I have not seen examples of Pod that includes storyboards. If you know of any pods that share their storyboard, let me know too.
我还没有看到包含故事板的 Pod 示例。如果您知道任何共享故事板的 Pod,也请告诉我。
回答by anka
There are two things to keep in mind.
有两件事要记住。
You add your pod resources via a predefined bundle like
s.resources = ["Resources/Pod.bundle"]
您可以通过预定义的包添加 pod 资源,例如
s.resources = ["Resources/Pod.bundle"]
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.
在这种情况下,您的包的内容将被复制到您的 xcode 项目中,而无需任何“进一步处理”。这意味着故事板或 xib 文件将不会被编译,也不会在您的项目中使用。
You can explicitly mention your storyboard/nib files like
s.resources = ["Resources/**/*.storyboard"]
您可以明确提及您的故事板/笔尖文件,例如
s.resources = ["Resources/**/*.storyboard"]
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.
在这种情况下,故事板将被编译并在您的项目中可用。这样做的缺点(在撰写本文时)是您不能使用本地化的故事板,因为所有故事板都将在您的包的根位置进行处理和复制。因此,不同.lproj
文件夹中具有相同名称的故事板将被覆盖。
回答by Keith Smiley
You want the resources
option. Here are some specs that include theirs:
你想要这个resources
选项。以下是包括他们的一些规格:
JCAutocompletingSearch/0.9.2/JCAutocompletingSearch.podspec
JCAutocompletingSearch/0.9.3/JCAutocompletingSearch.podspec
JCAutocompletingSearch/0.9.4/JCAutocompletingSearch.podspec
JCAutocompletingSearch/0.9.5/JCAutocompletingSearch.podspec
JCAutocompletingSearch/0.9.6/JCAutocompletingSearch.podspec
Keystone-Contacts-iOS/1.1.4/Keystone-Contacts-iOS.podspec
LumberHymanConsole/2.0.0/LumberHymanConsole.podspec
LumberHymanConsole/2.0.1/LumberHymanConsole.podspec
Mixpanel/2.1.0/Mixpanel.podspec
Mixpanel/2.2.0/Mixpanel.podspec
Mixpanel/2.2.1/Mixpanel.podspec
Mixpanel/2.2.2/Mixpanel.podspec
Mixpanel/2.2.3/Mixpanel.podspec
Mixpanel/2.3.0/Mixpanel.podspec
Mixpanel/2.3.1/Mixpanel.podspec
Mixpanel/2.3.2/Mixpanel.podspec
Mixpanel/2.3.4/Mixpanel.podspec
Mixpanel/2.3.5/Mixpanel.podspec
OpenBLE/1.0.0/OpenBLE.podspec
回答by Varun Naharia
I solved my problem by using this line code to get bundle
我通过使用此行代码获取捆绑包解决了我的问题
let bundle = Bundle(for: type(of: self))
回答by tilo
I currently have the same issue here. While not answering the question itself, I'd like to provide additional information that most likely is valid in your case, too:
我目前在这里遇到同样的问题。虽然不回答问题本身,但我想提供最有可能对您的情况有效的其他信息:
Calling
打电话
NSString *path = [bundle pathForResource:@"MyStoryboard" ofType:@"storyboard"];
NSLog(@"path: %@",path);
will print
将打印
/var/mobile/Containers/Bundle/Application/_identifier_/MyApp.app/MyBundle.bundle/Base.lproj/MyStoryboard.storyboard
i.e. the storyboard itself is found, but not loadable "the normal way".
即找到故事板本身,但不能“以正常方式”加载。