【问题标题】:Loading localized xib file from resource bundle (not main)从资源包(非主)加载本地化的 xib 文件
【发布时间】:2015-06-03 00:14:41
【问题描述】:

我使用 CocoPad 创建了一个资源包,其中包含本地化字符串、图像和 xib 文件。我在加载本地化字符串和图像时没有问题,但我在使用类似方法加载 xib 文件时遇到问题。这是我尝试过的一种方法:

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];

我得到了 'NSInternalInconsistencyException',原因:'Could not load NIB in bundle: 'NSBundle (not yet loaded)' with name

我已经把nibBundle中的文件打印出来了,文件就在那里。

【问题讨论】:

    标签: ios objective-c localization cocoapods


    【解决方案1】:

    我刚刚在Apple Developer web 网站上看到了

    在 UIKit 中,应用程序只能从它们的主包中加载 nib 文件,因此需要的选项更少。但我想知道是否有其他选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-10
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 2013-05-01
      • 2010-11-13
      • 1970-01-01
      • 2021-09-01
      相关资源
      最近更新 更多