简体   繁体   English

从资源包中加载本地化的xib文件(不是主要的)

[英]Loading localized xib file from resource bundle (not main)

I have created a resource bundle using CocoPad which contains localized strings, images and xib files. 我使用CocoPad创建了一个资源包,其中包含本地化的字符串,图像和Xib文件。 I have no problem loading localized strings and images but I am having problem loading xib files using a similar approach. 加载本地化的字符串和图像没有问题,但是使用类似方法加载xib文件时遇到问题。 Here is One of the methods I tried: 这是我尝试的方法之一:

NSString *nibName = @"MyTestViewController";
NSBundle *resourceBundle = [NSBundle bundleWithURL:[[NSBundle mainBundle]   URLForResource:@"MyTestResources"                                                        withExtension:@"bundle"]];


NSString* path= [resourceBundle pathForResource:@"en" ofType:@"lproj"];
NSBundle* nibBundle = [NSBundle bundleWithPath:path];

return [[MyTestViewController alloc] initWithNibName:nibName bundle:nibBundle];

I got 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (not yet loaded)' with name 我收到“ NSInternalInconsistencyException”,原因:“无法在捆绑包中加载NIB:“ NSBundle(尚未加载)”,名称为

I have printed out the files in the nibBundle and the file is there. 我已经打印出了nibBundle中的文件,并且文件在那里。

I just saw in the Apple Developer web site that 我刚刚在Apple Developer网站上看到

In UIKit, applications can load nib files only from their main bundle and so fewer options are needed. 在UIKit中,应用程序只能从其主捆绑包中加载nib文件,因此需要的选项更少。 But I want to know if there is any other alternatives. 但我想知道是否还有其他选择。

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

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