ios 无法加载捆绑包中的 NIB

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5337337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:15:21  来源:igfitidea点击:

Could not load NIB in bundle

iosiphonexcodetitaniumappcelerator

提问by Goje87

I am trying to integrate Janrain Engage as custom module with Appcelerator Titanium. I have created a sample module and dragged the JREngage folder to the sample module xcodeproj as indicated in the Jainrain's documentation.

我正在尝试将 Janrain Engage 作为自定义模块与 Appcelerator Titanium 集成。我创建了一个示例模块并将 JREngage 文件夹拖到示例模块 xcodeproj 中,如 Jainrain 的文档中所示。

Now I give build command to this project, then execute the ./build.pyand then finally I execute the titanium runcommand. It launches the application in simulator with a blank screen and immediately crashes throwing the following error.

现在我给这个项目生成命令,然后执行./build.py,最后我执行titanium run命令。它以空白屏幕在模拟器中启动应用程序,并立即崩溃并抛出以下错误。

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/abhilash/Library/Application Support/iPhone Simulator/4.2/Applications/CA167346-4091-4E16-B841-955D1D391713/test.app> (loaded)' with name 'JRProvidersController''

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法加载捆绑包中的 NIB:”NSBundle </Users/abhilash/Library/Application Support/iPhone Simulator/4.2/Applications/CA167346-4091-4E16-B841-93915131D test.app>(已加载)',名称为'JRProvidersController''

Why could this error be occurring?

为什么会发生此错误?

回答by sevenpounds

Visit the properties of the .xib files in the file inspector ,the property "Target Membership" pitch on the select box, then your xib file was linked with your target

在文件检查器中访问 .xib 文件的属性,在选择框中选中“Target Membership”属性,然后您的 xib 文件与您的目标相关联

回答by kunalg

In Targets -> Build Phases

Targets -> Build Phases

Make sure the .xib is added to Copy Bundle Resources, if it is not present then add .xib file.

确保将 .xib 添加到 中Copy Bundle Resources,如果不存在则添加 .xib 文件。

回答by chings228

try to find out all

尝试找出所有

XXXController = [[XXXControlloer alloc] initWithNibName:@"XXXController" bundle:nil];

in your code, and make sure that XXXControllerare spelled correctly

在您的代码中,并确保XXXController拼写正确

回答by creator_11

I had the same problem (exception 'Could not load NIB in bundle: ..') after upgrading my xcode from 3.2 to 4.02. Whereas deploying of my app with Xcode 3.2 worked fine it crashes with xcode 4 raising the exception mentioned above - but only when I tried to deploy to the IOS Simulator (v.4.2). Targeting the IOS device (v.4.1) acted also with Xcode 4.

将我的 xcode 从 3.2 升级到 4.02 后,我遇到了同样的问题(异常“无法在包中加载 NIB:..”)。虽然使用 Xcode 3.2 部署我的应用程序运行良好,但它会在 xcode 4 崩溃时引发上述异常 - 但仅当我尝试部署到 IOS Simulator (v.4.2) 时。针对 IOS 设备 (v.4.1) 也适用于 Xcode 4。

It turned out (after hours of desperately scrabbling around) that the reason was an almost "hidden" setting in the .xib-file:

事实证明(经过几个小时的拼命挣扎)原因是 .xib 文件中的一个几乎“隐藏”的设置:

Visit the properties of the .xib files in the file inspector: The property 'Location' was set to 'Relative to Group' for all .xib files. I changed it to 'Relative to project' and voila: all .xib files now are correctly loaded in IOS simulator !

在文件检查器中访问 .xib 文件的属性:对于所有 .xib 文件,属性“位置”被设置为“相对于组”。我将其更改为“相对于项目”,瞧:所有 .xib 文件现在都已正确加载到 IOS 模拟器中!

I have no clue what's the reason behind that for this odd Xcode4 behavior but maybe it's worth to make an attempt ?

我不知道这种奇怪的 Xcode4 行为背后的原因是什么,但也许值得尝试一下?

回答by Tibidabo

In my case it was very weird (use a storyboard): For some reason it changed from "Main storyboard file base name" to "Main nib file base name" in the plist.

就我而言,它非常奇怪(使用故事板):出于某种原因,它在 plist 中从“主故事板文件库名称”更改为“主 nib 文件库名称”。

Changing back to "Main storyboard file base name" (UIMainStoryboardFile) solved the issue

改回“主故事板文件基本名称”(UIMainStoryboardFile)解决了这个问题

回答by Hanuman

the error means that there is no .xib file with "JRProvidersController"name. recheck whether JRProvidersController.xibexists.

错误意味着没有带"JRProvidersController"名称的.xib 文件。重新检查是否JRProvidersController.xib存在。

you will load .xib filewith

您将加载.xib file

controller = [[JRProvidersController alloc] initWithNibName:@"JRProvidersController" bundle:nil];

回答by Tom Howard

Using a custom Swift view in an Objective-C view controller (yes, even after importing the <<PROJECT NAME>>-Swift.hfile), I'd tried to load the nib using:

在 Objective-C 视图控制器中使用自定义 Swift 视图(是的,即使在导入<<PROJECT NAME>>-Swift.h文件之后),我尝试使用以下方法加载笔尖:

MyCustomView *customView = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([MyCustomView class]) owner:self options:nil] objectAtIndex:0];

...but NSStringFromClass([MyCustomView class])returns <<PROJECT NAME>>.MyCustomViewand the load fails. TL;DR All worked well loading the nib using a string literal:

...但NSStringFromClass([MyCustomView class])返回<<PROJECT NAME>>.MyCustomView并且加载失败。TL;DR 使用字符串文字加载笔尖都运行良好:

MyCustomView *customView = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil] objectAtIndex:0];

回答by Will Larche

I had this problem with a storyboard and the nib was called something like 'bKD-J3-fhr-view-ZSR-8m-2da'.

我的故事板有这个问题,笔尖被称为“bKD-J3-fhr-view-ZSR-8m-2da”。

It was because I was trying to add a subview to self.view in a view controller's init (withCoder). Self.view doesn't exist yet.

这是因为我试图在视图控制器的初始化(withCoder)中向 self.view 添加一个子视图。Self.view 尚不存在。

Moved it to viewDidLoad and all better!

将它移动到 viewDidLoad 并且一切都更好!

回答by Michael Brian Bentley

With the build target being one of my iOS devices, I right-clicked the Product file (xyzw.app) and selected the Show in Finder popup item. It opened a window with the xyzw.app inside; I opened the bundle using Show Package Contents and saw all the files I expected, except one file, the one it was complaining about, with a capital I instead of a lower-case i in the name (zoomieVIew.nib instead of zoomieView.nib). I had noticed the uppercase I in the file name of the xib, and changed it and rebuilt; apparently Xcode left the generated .nib name the way it was. I deleted zoomieVIew.nib in the bundle, rebuilt, and Xcode duly recreated the file as zoomieView.nib. The app started to work on the device.

构建目标是我的 iOS 设备之一,我右键单击产品文件 (xyzw.app) 并选择在 Finder 弹出项中显示。它打开了一个窗口,里面有 xyzw.app;我使用 Show Package Contents 打开了包,看到了我期望的所有文件,除了一个文件,它抱怨的那个文件,在名称中用大写的 I 而不是小写的 i(zoomieVIew.nib 而不是 zoomieView.nib )。我注意到xib的文件名中的大写I,并对其进行了更改和重建;显然 Xcode 保留了生成的 .nib 名称。我删除了包中的 zoomieVIew.nib,重新构建,Xcode 将文件重新创建为 zoomieView.nib。该应用程序开始在设备上运行。

回答by iChirag

Have look on project

看项目

Target -> Buid Phases -> Copy Bundle Resources

Target -> Buid Phases -> Copy Bundle Resources

You will find your xib/storyborad with red color.

你会发现你的 xib/storyborad 是红色的。

Just remove it.Also remove all references of missing file from project.

只需删除它。同时从项目中删除所有丢失文件的引用。

Now drag this storyboard/xib file again to this Copy Bundle Resources.It will still show you file with red color but dont worry about it.

现在再次将这个 storyboard/xib 文件拖到这里。Copy Bundle Resources它仍然会显示红色的文件,但不要担心。

Just clean and build project.

只需清理并构建项目。

Now you will get your project running again successfully!!

现在您将再次成功运行您的项目!!