简体   繁体   English

静态库上的Xib文件

[英]Xib file on static library

I'm taking over a project I did not start and I'm still a junior, so I need some help to clarify my mind. 我正在接管一个我尚未开始的项目,但我仍然是大三,因此我需要一些帮助来澄清我的想法。 I'm developing a library for iOS 7.0 and up. 我正在为iOS 7.0及更高版本开发一个库。 This library is then distributed trough cocoapods. 然后将该库通过可可足类分发。

I've build a custom view and how I have a .xib file containing it. 我已经建立了一个自定义视图,以及如何拥有一个包含它的.xib文件。 It works perfectly in my dev app (because I'm using directly the code), but when I test it in my staging app (which loads the library trough a local pod) I get 它在我的开发应用程序中完美运行(因为我直接使用了代码),但是当我在暂存应用程序(通过本地容器加载库)中对其进行测试时,我得到了

NSInternalInconsistencyException Could not load NIB in bundle: 'NSBundle </Users/Jack/Library/Developer/CoreSimulator/Devices/899B54FC-8A37-4182-9D89-109251B58555/data/Containers/Bundle/Application/36A3B225-AEF2-42B7-8AEC-5D930F4C4BCA/StagingApp.app> (loaded)' with name 'CheckBoxWithText''

The .xib file is in the copy file build phase and is part of the target I'm using to build the library. .xib文件处于复制文件构建阶段,并且是我用来构建库的目标的一部分。

I'm loading the xib like this 我正在像这样加载XIB

[[NSBundle mainBundle] loadNibNamed:@"CheckBoxWithText" owner:self options:nil];

But it crashes as soon as the components gets loaded on screen. 但是,一旦将组件加载到屏幕上,它就会崩溃。
Some people were saying to use the bundle of your library, but I don't think my library has an identifier ( can't see it on info). 有人说要使用您的图书馆捆绑包,但我认为我的图书馆没有标识符(无法在信息中看到它)。
I tried using 我尝试使用

[[NSBundle bundleWithIdentifier:@"com.company.project"] loadNibNamed:@"CheckBoxWithText" owner:self options:nil];

but it does not load anything. 但不会加载任何内容。

I've spent the afternoon reading possible solution but now I've a lot of confusion in my head. 我花了一个下午的时间阅读可能的解决方案,但是现在我脑子里很困惑。

A static library (like mine) is not supposed to contain resources like xib, yet I'm packing some images with it. 静态库(如我的静态库)不应包含xib之类的资源,但是我正在用它包装一些图像。 Am I missing something here? 我在这里想念什么吗?
I've read a tutorial about a guy who achieved this using a budle target, but I haven't really understood how he did it and how would I use that target given that I'm supposed to use my aggregate target to build the library. 我读过一个关于一个使用budle目标实现此目标的人的教程 ,但是我真的不了解他是如何做到的,以及鉴于我应该使用汇总目标来构建库,我将如何使用该目标。

A dynamic framework would solve the problem if not for the fact that I can't use it on iOS7.0. 如果不是因为我不能在iOS7.0上使用动态框架,那么动态框架将解决该问题。

Is my only option to build the layout programmatically? 我唯一以编程方式构建布局的选择吗?
Or am I just missing something and it's possible to pack the .xib file? 还是我只是缺少一些东西,可以打包.xib文件?

CocoaPods doesn't seem to pick up .xib files when you specify them using resources in your .podspec . 的CocoaPods似乎并没有回暖.xib文件,当您指定它们使用resources在你的.podspec Using resource_bundles instead works fine. 使用resource_bundles可以正常工作。

So the .podspec would read: 因此.podspec将显示为:

s.resource_bundles = { 'CheckBoxWithText' => ['CheckBoxWithText.xib'] }

The Nib would be loaded like this: 笔尖将像这样加载:

NSBundle* bundle = [NSBundle bundleForURL:[NSBundle.mainBundle URLForResource:@"CheckBoxWithText"
        withExtension:@"bundle"]];
NSArray* nib = [bundle loadNibNamed:@"USACheckBoxWithText" owner:self options:nil];

Now there is another bug in CocoaPods which prevents asset catalogs to be loaded from resource_bundles . 现在,CocoaPods中存在另一个错误,该错误阻止从resource_bundles加载资产目录 You should avoid asset catalogs for now. 您现在应该避免资产目录。

Note that both bugs would be solved if you use iOS 8 as minimum and develop your Pod in Swift. 请注意,如果您至少使用iOS 8并在Swift中开发Pod,这两个错误都将得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM