简体   繁体   English

iOS8:如何从动态框架加载xib

[英]iOS8: How to load xib from Dynamic Framework

I am using Cocoapods pre-release 0.36 to build and deploy a private dynamic framework into an app bundle. 我正在使用Cocoapods预发布0.36来构建私有动态框架并将其部署到应用程序包中。 I am using the resources attribute to copy xibs, and they show up in the app bundle. 我使用resources属性来复制xibs,它们出现在app bundle中。

s.subspec 'Views' do |ss|
    ...
    ss.resources = ['All/My/Folders/**/*.{xib,png}']
    ...

I am trying to load reusable controls from the xibs like this: 我试图从xib加载可重用的控件,如下所示:

NSBundle.mainBundle().loadNibNamed("MyXib", owner:loader, options:nil)

but this is failing as it cannot find the xib in my embedded sub framework. 但这是失败的,因为它无法在我的嵌入式子框架中找到xib。 The actual xib (nib) paths follow the pattern:' 实际的xib(nib)路径遵循以下模式:'

./Frameworks/MyPrivateFramework.framework/MyXib.nib

My question is, is there a simple, code agnostic way of loading the xib that will work when packaged in an iOS 8 framework - or do I have to explicitly hardcode in the above path? 我的问题是,是否有一种简单的,代码无关的加载xib的方式,当在iOS 8框架中打包时可以工作 - 或者我是否必须在上述路径中明确硬编码? The above loading code worked until I think the dynamic framework change. 上面的加载代码工作,直到我认为动态框架发生了变化。

Thanks 谢谢

From this post here: 从这篇文章:

http://artsy.github.io/blog/2015/01/04/cocoapods-and-frameworks/ http://artsy.github.io/blog/2015/01/04/cocoapods-and-frameworks/

I arrived at the agnostic solution of getting the framework bundle from a class within, ie: 我到达了从一个类中获取框架包的不可知解决方案,即:

NSBundle(forClass: ClassInFramework.self)

and then loading the xib from that: 然后从中加载xib:

NSBundle(forClass: ClassInFramework.self)
    .loadNibNamed("ClassInFramework", owner:loader, options:nil)

and that worked. 那很有效。

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

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