在iOS项目中使用包时出错/如何创build正确的包?

我试图在iOS项目中包含一个静态库。 我导入了整个静态库项目,然后我把这个库链接到“目标依赖关系”和“链接二进制文件库”中,如下所示: http : //www.applausible.com/blog/?p=657

但是当testing应用程序时,我得到这个错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/alexis/Library/Application Support/iPhone Simulator/5.0/Applications/9811107D-0D7E-4178-ACCE-BF43E3043770/PlazappPartnerTest.app> (loaded)' with name 'LauncherView'' *** First throw call stack: (0x188a052 ...... 

我想它不能访问.xib文件,但因为它包含在我的库中,我不知道为什么。 如何使主项目“看”.xib文件? (如果这实际上是问题…)

编辑:

我试图做一个包含.xib文件的包,并将其包含到我的主项目中,但是我不能使用这个包。 我试过这个:

 NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"BundleName" ofType:@"bundle"]; NSBundle *bundle = [NSBundle bundleWithPath:bundlePath]; NSError *error; [bundle loadAndReturnError:&error]; NSLog(@"bundle error : %@", [error userInfo]); 

我得到这个错误:

 NSLocalizedDescription = "The bundle \U201cBundleName.bundle\U201d couldn\U2019t be loaded because its executable couldn\U2019t be located."; NSLocalizedFailureReason = "The bundle\U2019s executable couldn\U2019t be located."; NSLocalizedRecoverySuggestion = "Try reinstalling the bundle."; 

有什么问题?

我想我不能加载包含非可执行资源(如.xib文件)的包。 我对吗?

但是,那么如何从bundle中加载我的.xib呢?

在Cocoa编程中,经常有不止一种方法来获得一个包。 我已经成功了:

 NSBundle *libBundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"BundleName" withExtension:@"bundle"]]; 

然后用这个加载笔尖:

 MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:libBundle]; 

您对loadAndReturnError:进行的特定调用loadAndReturnError:加载包的可执行代码。 由于这个包可能没有任何可执行代码,只是库需要的资源集合,它会给你这个错误。

编辑 (回应评论):

我通过向捆绑包的库项目添加新的目标来制作捆绑包。 从Mac OS X捆绑包模板开始,我将所有图像,.xib和其他资源添加到“复制捆绑软件资源”构build阶段。 我将基础SDK更改为iOS(最新)。 然后我把这个包添加到库的依赖项和最终应用程序的“Copy Bundle Resources”构build阶段。

如果您只是尝试将.xib文件添加到文件夹方法,则.xibs不会编译为nib,而iOS无法读取它们。