简体   繁体   English

从框架加载nib文件

[英]Loading nib file from framework

I have a nib file created from Interface builder which I have inserted in a framework as bundle resources and added to my project. 我有一个从“接口”构建器创建的nib文件,该文件已作为捆绑资源插入框架中并添加到我的项目中。 I am trying to load the nib file from the framework but not sure how to load it for a ViewController. 我正在尝试从框架加载nib文件,但不确定如何为ViewController加载它。 Could anyone share any thoughts as of how to load the nib file from main bundle of the framework resource folder? 关于如何从框架资源文件夹的主包加载nib文件,谁能分享任何想法?

Thanks. 谢谢。

Okay so after wondering around a bit, I finally got it working. 好吧,在想了一下之后,我终于开始工作了。 Below is the content as of how I loaded nib file from external framework, might help someone in future. 以下是我如何从外部框架加载nib文件的内容,将来可能会对某人有所帮助。

NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:@"TheFrameworkName" ofType:@"framework"];

NSLog(@"the bundle: %@",resourceBundlePath);

NSBundle* languageBundle = [NSBundle bundleWithPath:resourceBundlePath];
[languageBundle load];

NSLog(@"The bundle desc: %@",[languageBundle description]);

self.scanManual = [[Scanner alloc] initWithNibName:@"Resources/Scanner" bundle:languageBundle];

Since I was getting (null) contents in first few tries, its a good way of checking of the bundle is getting loaded by keeping NSLog. 由于我在最初的几次尝试中都获得了(空)内容,因此通过保持NSLog来加载捆绑包是一种检查捆绑包的好方法。 Thanks again to stackoverflow community 再次感谢stackoverflow社区

I am not sure that this will work for xib but This is how i am loading my images from bundle check if it is working for you. 我不确定这是否适用于xib,但这是我从捆绑加载图像的方式,检查它是否对您有用。

But make sure that when you add your folder you should click on second radion button like image. 但是请确保在添加文件夹时,应单击第二个单选按钮,例如image。

在此处输入图片说明

imageArray = (NSMutableArray *)[[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:@"Beauty Shots_iPad"];

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

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